Example #1
0
// content
$content = "\r\n    <table style='margin-top: 30px' width='100%' cellspacing='0' cellpadding='0'>\r\n        <thead>\r\n            <tr>\r\n                <td class='cell-header' style='text-align: center' width='25px'>#</td>\r\n                <td class='cell-header'>รหัสสินค้า</td>\r\n                <td class='cell-header'>รายการ</td>\r\n                <td class='cell-header' style='text-align: right'>น้ำหนัก(กรัม)</td>\r\n                <td class='cell-header' style='text-align: right' width='60px'>ราคา</td>\r\n                <td class='cell-header' style='text-align: right' width='50px'>จำนวน</td>\r\n                <td class='cell-header' style='text-align: right' width='70px'>รวม</td>\r\n            </tr>\r\n        </thead>\r\n        <tbody>";
$sum = 0;
$sum_qty = 0;
$i = 1;
$sum_weight = 0;
// table body
foreach ($billSaleDetail as $r) {
    $product_code = $r->bill_sale_detail_barcode;
    $product_name = $r->product->product_name;
    $product_price = $r->bill_sale_detail_price;
    $product_qty = $r->bill_sale_detail_qty;
    $bill_sale_detail_price_vat = $r->bill_sale_detail_price_vat;
    // find name of product
    if (empty($product_name)) {
        $productPrice = BarcodePrice::model()->findByPk($product_code);
        $fk = $productPrice->barcode_fk;
        $productRelate = Product::model()->findByAttributes(array('product_code' => $fk));
        $product_name = $productRelate->product_name . " ({$productPrice->name})";
    }
    $price_per_row = $product_qty * $product_price;
    $sum += $price_per_row;
    $sum_qty += $product_qty;
    $price_per_row = number_format($price_per_row);
    $product_price = number_format($product_price);
    $product_qty = number_format($product_qty);
    $vat = number_format($bill_sale_detail_price_vat, 2);
    $product = Product::model()->findByAttributes(array('product_code' => $product_code));
    $weight = $product->weight;
    $sum_weight += $weight;
    if (empty($weight)) {
Example #2
0
 ?>
         <?php 
 $price = $billSaleDetail['bill_sale_detail_price'];
 $qty = $billSaleDetail['bill_sale_detail_qty'];
 $total_price_in_row = $price * $qty;
 $sumInput += $total_price_in_row;
 ?>
         <tr>
           <td style="text-align: right">
             <?php 
 echo $n++;
 ?>
           </td>
           <td>
             <?php 
 $barcodePrice = BarcodePrice::model()->findByAttributes(array('barcode' => $billSaleDetail['bill_sale_detail_barcode']));
 if (!empty($barcodePrice)) {
     $product_name = $barcodePrice->product->product_name . ' - ' . $barcodePrice->name . ' (' . $barcodePrice->qty_sub_stock . ')';
 } else {
     $product_name = $billSaleDetail['product_name'];
 }
 ?>
             <?php 
 echo $product_name;
 ?>
           </td>
           <td style="text-align: center">
             <?php 
 echo Util::mysqlToThaiDate($billSaleDetail['bill_sale_pay_date']);
 ?>
           </td>
Example #3
0
 public function actionEndSale()
 {
     $this->checkLogin();
     $saleTemps = SaleTemp::model()->findAllByAttributes(array('user_id' => (int) Yii::app()->request->cookies['user_id']->value));
     if (!empty($saleTemps)) {
         // find member_id
         $member_code = Util::input($_POST['txt_member_code']);
         $member_id = 0;
         if (!empty($member_code)) {
             $member = Member::model()->findByAttributes(array('member_code' => $member_code));
             if (!empty($member)) {
                 $member_id = $member->member_id;
             }
         }
         // sale_status
         if ($_POST['sale_status'] == 'cash') {
             $saleStatus = 'pay';
         } else {
             $saleStatus = 'credit';
         }
         $created_date = Util::input($_POST['BillSale']['bill_sale_created_date']);
         $created_date = Util::thaiToMySQLDate($created_date);
         // bill sale
         $modelBillSale = new BillSale();
         $modelBillSale->bill_sale_created_date = $created_date;
         $modelBillSale->bill_sale_status = $saleStatus;
         $modelBillSale->member_id = $member_id;
         $modelBillSale->bill_sale_vat = Util::input($_POST['bill_sale_vat']);
         $modelBillSale->user_id = (int) Yii::app()->request->cookies['user_id']->value;
         $modelBillSale->branch_id = Util::input($_POST['BillSale']['branch_id']);
         $modelBillSale->bonus_price = Util::input($_POST['bonus_price']);
         $modelBillSale->out_vat = Util::input($_POST['out_vat']);
         $modelBillSale->vat_type = Util::input($_POST['hidden_vat_type']);
         $modelBillSale->input_money = Util::input($_POST['hidden_input']);
         $modelBillSale->return_money = Util::input($_POST['hidden_return_money']);
         $modelBillSale->total_money = Util::input($_POST['hidden_total']);
         $modelBillSale->customer_name = Util::input($_POST['customer_name']);
         $modelBillSale->customer_tel = Util::input($_POST['customer_tel']);
         $modelBillSale->customer_tax = Util::input($_POST['customer_tax']);
         $modelBillSale->customer_address = Util::input($_POST['customer_address']);
         if ($_POST['sale_status'] == 'cash') {
             $_time = date("h:i:s");
             $modelBillSale->bill_sale_pay_date = $created_date . " " . $_time;
         }
         if ($modelBillSale->save()) {
             // store data bill_sale_detail from session to database
             $i = 0;
             $qtys = $_POST['qtys'];
             foreach ($saleTemps as $saleTemp) {
                 $qty_for_sub_stock = $qtys[$i];
                 $model = new BillSaleDetail();
                 $model->bill_id = $modelBillSale->bill_sale_id;
                 $model->bill_sale_detail_barcode = $saleTemp->barcode;
                 $model->bill_sale_detail_price = $saleTemp->price;
                 $model->bill_sale_detail_qty = $saleTemp->qty;
                 $model->bill_sale_detail_price_vat = $saleTemp->price * 0.07000000000000001;
                 $model->old_price = $saleTemp->old_price;
                 $model->save();
                 // sub stock
                 $product_code = $saleTemp->barcode;
                 // find by barcode
                 $product = Product::model()->findByAttributes(array('product_code' => $product_code));
                 if (empty($product)) {
                     // find by pack barcode
                     $product = Product::model()->findByAttributes(array('product_pack_barcode' => $product_code));
                 }
                 if (empty($product)) {
                     // find by barcode_price
                     $barcodePrice = BarcodePrice::model()->findByAttributes(array('barcode' => $product_code));
                     $product = $barcodePrice->getProduct();
                 }
                 if (!empty($saleTemp->qty_per_pack)) {
                     $qty_for_sub_stock = $saleTemp->qty_per_pack * $qty_for_sub_stock;
                 }
                 $qty = $product->product_quantity - $qty_for_sub_stock;
                 $product->product_quantity = $qty;
                 $product->save();
                 $i++;
             }
             // save to tb_product_serial
             $serials = $_POST['serials'];
             $hidden_product_codes = $_POST['hidden_product_codes'];
             if (!empty($serials)) {
                 $i = 0;
                 foreach ($serials as $serial) {
                     $product_code = $hidden_product_codes[$i];
                     $productSerial = new ProductSerial();
                     $productSerial->product_code = $product_code;
                     $productSerial->serial_no = $serial;
                     $productSerial->product_start_date = new CDbExpression('NOW()');
                     $productSerial->bill_sale_id = $modelBillSale->bill_sale_id;
                     // expire date
                     if (!empty($r['product_expire_date'])) {
                         $expire_date = Util::thaiToMySQLDate($r['product_expire_date']);
                         $productSerial->product_expire_date = $expire_date;
                     }
                     $productSerial->save();
                 }
             }
             // keep last bill_id
             $output = array('last_bill_id' => $modelBillSale->bill_sale_id, 'message' => 'success');
             echo CJSON::encode($output);
         } else {
             echo 'can not save modal bill sale';
         }
     } else {
         echo 'saleTemp is a empty';
     }
 }
Example #4
0
 public function actionSaveProductPriceBarCode()
 {
     $this->checkLogin();
     if (!empty($_POST)) {
         $barcodes = Util::input($_POST['barcode']);
         $price_befores = Util::input($_POST['price_before']);
         $prices = Util::input($_POST['price']);
         $qtys = Util::input($_POST['qty']);
         $names = Util::input($_POST['name']);
         $barcode_fk = Util::input($_POST['product_code']);
         if (!empty($barcodes)) {
             $size = count($barcodes);
             // delete
             BarcodePrice::model()->deleteAllByAttributes(array('barcode_fk' => $barcode_fk));
             // insert
             for ($i = 0; $i < $size; $i++) {
                 if ($prices[$i] != 0) {
                     $barcodePrice = new BarcodePrice();
                     $barcodePrice->barcode = $barcodes[$i];
                     $barcodePrice->price_before = $price_befores[$i];
                     $barcodePrice->price = $prices[$i];
                     $barcodePrice->qty_sub_stock = $qtys[$i];
                     $barcodePrice->name = $names[$i];
                     $barcodePrice->barcode_fk = $barcode_fk;
                     $barcodePrice->save();
                 }
             }
             echo 'success';
         }
     }
 }
Example #5
0
 public function actionSale()
 {
     if (!empty($_POST)) {
         $product_name;
         $qty_sub_stock;
         $old_price;
         // find product
         $product = Product::model()->findByAttributes(array('product_code' => Util::input($_POST['product_code'])));
         // not found find from barcode_price
         if (empty($product)) {
             $barcodePrice = BarcodePrice::model()->findByAttributes(array('barcode' => Util::input($_POST['product_code'])));
             if (!empty($barcodePrice)) {
                 $product = $barcodePrice->getProduct();
                 $product_name = $product->product_name . " ( {$barcodePrice->name} )";
                 $qty_sub_stock = $barcodePrice->qty_sub_stock;
                 $old_price = $barcodePrice->price_before;
             }
         } else {
             $product_name = $product->product_name;
             $qty_sub_stock = $product->product_total_per_pack;
         }
         // found product
         if (!empty($product)) {
             // find price
             $price = $product->product_price;
             $old_price = $product->product_price_buy;
             // find default price and send price
             $sale_condition = Util::input($_POST['sale_condition']);
             if ($sale_condition == 'one') {
                 // ขายปลีก
                 $price = $product->product_price;
             } else {
                 // ขายส่ง
                 $price = $product->product_price_send;
             }
             // find by barcode price
             $barcodePrice = BarcodePrice::model()->findByAttributes(array('barcode' => Util::input($_POST['product_code'])));
             if (!empty($barcodePrice)) {
                 $price = $barcodePrice->price;
                 $old_price = $barcodePrice->price_before;
                 $product_name = $product->product_name . " ( {$barcodePrice->name} )";
                 $qty_sub_stock = $barcodePrice->qty_sub_stock;
             }
             // find between price
             $productPrice = ProductPrice::model()->find(array('condition' => '
         product_barcode = :product_barcode
         AND 
         (qty <= :qty AND :qty <= qty_end)
       ', 'params' => array('qty' => (int) Util::input($_POST['qty']), 'product_barcode' => Util::input($_POST['product_code']))));
             if (!empty($productPrice)) {
                 if ($sale_condition == 'one') {
                     $price = $productPrice->price;
                 } else {
                     $price = $productPrice->price_send;
                 }
             }
             // find qty_sub_stock
             $qty_sub_stock = $product->product_total_per_pack;
             if (!empty($barcodePrice)) {
                 $qty_sub_stock = $barcodePrice->qty_sub_stock;
             }
             // default qty_sub_stock
             if ($qty_sub_stock == 0) {
                 $qty_sub_stock = 1;
             }
             // check condition
             $configSoftware = ConfigSoftware::model()->find();
             $is_sale = false;
             if ($configSoftware->sale_out_of_stock == 'yes') {
                 $is_sale = true;
             } else {
                 if ($product->product_quantity > 0) {
                     $is_sale = true;
                 }
             }
             if ($is_sale) {
                 // save to temp
                 $saleTemp = new SaleTemp();
                 $saleTemp->barcode = Util::input($_POST['product_code']);
                 $saleTemp->name = $product_name;
                 $saleTemp->serial = Util::input($_POST['serial']);
                 $saleTemp->price = str_replace(',', '', $price);
                 $saleTemp->qty = str_replace(',', '', $_POST['qty']);
                 $saleTemp->qty_per_pack = $qty_sub_stock;
                 $saleTemp->user_id = Yii::app()->request->cookies['user_id']->value;
                 $saleTemp->branch_id = (int) Util::input($_POST['branch_id']);
                 $saleTemp->pk_temp = rand(1, 99999);
                 $saleTemp->created_at = new CDbExpression('NOW()');
                 $saleTemp->old_price = $old_price;
                 // save and update stock
                 if ($saleTemp->save()) {
                     Yii::app()->session['branch_id'] = (int) Util::input($_POST['branch_id']);
                     echo 'success';
                 }
             } else {
                 echo Yii::t("lang", "product_out_of_stock");
             }
         }
     }
 }