Пример #1
0
 public function saleClientCookie($client_id)
 {
     //$this->clearAll();
     $sale_item = SaleClientCookie::model()->findAll('client_id=:client_id', array(':client_id' => $client_id));
     if (isset($sale_item)) {
         foreach ($sale_item as $row) {
             $this->addItem($row->item_id, $row->quantity, $row->discount_amount, $row->price, $row->description);
         }
     }
 }
Пример #2
0
 public function saveSaleCookie($items, $customer_id, $employee_id, $comment)
 {
     if (count($items) == 0 && !isset($customer_id)) {
         return -1;
     }
     $transaction = Yii::app()->db->beginTransaction();
     try {
         $query = "delete from sale_client_cookie where client_id=:client_id";
         $command = Yii::app()->db->createCommand($query);
         $command->bindParam(":client_id", $customer_id, PDO::PARAM_INT);
         $command->execute();
         // Saving sale item to sale_item table
         foreach ($items as $line => $item) {
             if (substr($item['discount'], 0, 1) == '$') {
                 $discount_amount = substr($item['discount'], 1);
                 $discount_type = '$';
             } else {
                 $discount_amount = $item['discount'];
                 $discount_type = '%';
             }
             $cur_item_info = Item::model()->findbyPk($item['item_id']);
             //Saving frequency buy items for client
             $sale_client_cookie = new SaleClientCookie();
             $sale_client_cookie->client_id = $customer_id;
             $sale_client_cookie->item_id = $item['item_id'];
             $sale_client_cookie->quantity = $item['quantity'];
             $sale_client_cookie->cost_price = $cur_item_info->cost_price;
             $sale_client_cookie->unit_price = $cur_item_info->unit_price;
             $sale_client_cookie->price = $item['price'];
             // The exact selling price
             $sale_client_cookie->discount_amount = $discount_amount == null ? 0 : $discount_amount;
             $sale_client_cookie->discount_type = $discount_type;
             $sale_client_cookie->save();
         }
         $transaction->commit();
     } catch (Exception $e) {
         //$sale_id=$e; //Uncomment here for debuggin purpose
         $transaction->rollback();
         return -1;
     }
     //return $sale_id;
 }