97 lines
3.1 KiB
Ruby
97 lines
3.1 KiB
Ruby
class Transactions::SalesController < ApplicationController
|
|
before_action :set_transactions_sale, only: [:show, :edit, :update, :destroy]
|
|
|
|
# GET /transactions/sales
|
|
# GET /transactions/sales.json
|
|
def index
|
|
|
|
search_date = params[:date]
|
|
receipt_no = params[:receipt_no]
|
|
today = Date.today
|
|
|
|
if receipt_no.nil?
|
|
@sales = Sale.order("sale_id").page(params[:page])
|
|
#@products = Product.order("name").page(params[:page]).per(5)
|
|
else
|
|
@sales = Sale.search(receipt_no)
|
|
end
|
|
@sales = Kaminari.paginate_array(@sales).page(params[:page]).per(50)
|
|
respond_to do |format|
|
|
format.html # index.html.erb
|
|
format.json { render json: @sales }
|
|
end
|
|
end
|
|
|
|
# GET /transactions/sales/1
|
|
# GET /transactions/sales/1.json
|
|
def show
|
|
|
|
@sale = Sale.find(params[:id])
|
|
# @sale_receivables = SaleReceivable.where('sale_id = ?', @sale.id)
|
|
respond_to do |format|
|
|
format.html # show.html.erb
|
|
format.json { render json: @sale }
|
|
end
|
|
end
|
|
|
|
# GET /transactions/sales/new
|
|
def new
|
|
@transactions_sale = Sale.new
|
|
end
|
|
|
|
# GET /transactions/sales/1/edit
|
|
def edit
|
|
end
|
|
|
|
# POST /transactions/sales
|
|
# POST /transactions/sales.json
|
|
def create
|
|
@transactions_sale = Sale.new(transactions_sale_params)
|
|
|
|
respond_to do |format|
|
|
if @transactions_sale.save
|
|
format.html { redirect_to @transactions_sale, notice: 'Sale was successfully created.' }
|
|
format.json { render :show, status: :created, location: @transactions_sale }
|
|
else
|
|
format.html { render :new }
|
|
format.json { render json: @transactions_sale.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# PATCH/PUT /transactions/sales/1
|
|
# PATCH/PUT /transactions/sales/1.json
|
|
def update
|
|
respond_to do |format|
|
|
if @transactions_sale.update(transactions_sale_params)
|
|
format.html { redirect_to @transactions_sale, notice: 'Sale was successfully updated.' }
|
|
format.json { render :show, status: :ok, location: @transactions_sale }
|
|
else
|
|
format.html { render :edit }
|
|
format.json { render json: @transactions_sale.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# DELETE /transactions/sales/1
|
|
# DELETE /transactions/sales/1.json
|
|
def destroy
|
|
@transactions_sale.destroy
|
|
respond_to do |format|
|
|
format.html { redirect_to transactions_sales_url, notice: 'Sale was successfully destroyed.' }
|
|
format.json { head :no_content }
|
|
end
|
|
end
|
|
|
|
private
|
|
# Use callbacks to share common setup or constraints between actions.
|
|
def set_transactions_sale
|
|
@transactions_sale = Sale.find(params[:id])
|
|
end
|
|
|
|
# Never trust parameters from the scary internet, only allow the white list through.
|
|
def transactions_sale_params
|
|
params.require(:transactions_sale).permit(:cashier_id, :cashier_name, :requested_by, :requested_at, :receipt_no, :receipt_date, :customer_id, :payment_status, :sale_status, :total_amount, :total_discount, :total_tax, :tax_type, :grand_total, :rounding_adjustment, :amount_received, :amount_changed)
|
|
end
|
|
end
|