public function actionSetTotalDiscount()
 {
     if (Yii::app()->request->isPostRequest) {
         $data = array();
         $model = new SaleItem();
         $total_discount = $_POST['SaleItem']['total_discount'];
         $model->total_discount = $total_discount;
         if ($model->validate()) {
             Yii::app()->wshoppingCart->setTotalDiscount($total_discount);
         } else {
             $error = CActiveForm::validate($model);
             $errors = explode(":", $error);
             $data['warning'] = str_replace("}", "", $errors[1]);
         }
         $this->reload($data);
     }
 }
 public function copyEntireSuspendSale($sale_id)
 {
     $this->clearAll();
     $sale = Sale::model()->findbyPk($sale_id);
     $sale_item = SaleItem::model()->getSaleItem($sale_id);
     $payments = SalePayment::model()->getPayment($sale_id);
     foreach ($sale_item as $row) {
         if ($row->discount_type == '$') {
             $discount_amount = $row->discount_type . $row->discount_amount;
         } else {
             $discount_amount = $row->discount_amount;
         }
         $this->addItem($row->item_id, $row->quantity, $discount_amount, $row->price, $row->description);
     }
     foreach ($payments as $row) {
         $this->addPayment($row->payment_type, $row->payment_amount);
     }
     $this->setCustomer($sale->client_id);
     $this->setComment($sale->remark);
     $this->setTotalDiscount($sale->discount_amount);
     $this->setSaleId($sale_id);
 }
Example #3
0
 public function postSaleStore()
 {
     try {
         $input = Input::all();
         $sale = Sale::find($input['sale']);
         // Si no existe notaparcial y está pendiente es porque se está finalizando la remisión.
         if (!isset($input['notaparcial']) && $sale->status == 'pendiente') {
             $sitems = SaleItem::where('sale_id', '=', $input['sale'])->get();
             foreach ($sitems as $sitem) {
                 self::saveInStockTable($input['branch_id'], $sitem->article->id, $sitem->amount);
             }
             #foreach
             /*Cambiar el status en la tabla sale a finalizado*/
             $sale = Sale::find($input['sale']);
             $sale->status = 'finalizado';
             $sale->save();
         }
         $saleStore = new SaleStore();
         $saleStore->sale_id = $input['sale'];
         $saleStore->user_id = Auth::user()->id;
         $saleStore->comments = $input['comments'];
         $saleStore->save();
         return Redirect::to('sales/items/' . $input['sale']);
     } catch (Exception $e) {
         die('No se pudo disminuir el stock.');
     }
 }
Example #4
0
 public function getSaleItem($sale_id)
 {
     $model = SaleItem::model()->findAll('sale_id=:saleId', array(':saleId' => $sale_id));
     return $model;
 }
 public function actionSaleInvoiceItem($sale_id, $employee_id)
 {
     if (Yii::app()->user->checkAccess('report.index')) {
         $model = new SaleItem('search');
         $model->unsetAttributes();
         // clear any default values
         $payment = new SalePayment('search');
         //$payment->unsetAttributes();
         //$employee=Employee::model()->findByPk((int)$employee_id);
         //$cashier=$employee->first_name . ' ' . $employee->last_name;
         if (isset($_GET['SaleItem'])) {
             $model->attributes = $_GET['SaleItem'];
         }
         if (Yii::app()->request->isAjaxRequest) {
             Yii::app()->clientScript->scriptMap['*.js'] = false;
             //Yii::app()->clientScript->scriptMap['*.css'] = false;
             if (isset($_GET['ajax']) && $_GET['ajax'] == 'sale-item-grid') {
                 $this->render('sale_item', array('model' => $model, 'payment' => $payment, 'sale_id' => $sale_id, 'employee_id' => $employee_id));
             } else {
                 echo CJSON::encode(array('status' => 'render', 'div' => $this->renderPartial('sale_item', array('model' => $model, 'payment' => $payment, 'sale_id' => $sale_id, 'employee_id' => $employee_id), true, true)));
                 Yii::app()->end();
             }
         } else {
             $this->render('sale_item', array('model' => $model));
         }
     } else {
         throw new CHttpException(403, 'You are not authorized to perform this action');
     }
 }
Example #6
0
 public function ventaReciente()
 {
     $reciente = SaleItem::where('article_id', '=', $this->id)->orderBy('created_at', 'desc')->first();
     if (!empty($reciente)) {
         return $reciente->created_at;
     } else {
         return '2013-01-01';
     }
 }