Exemple #1
0
 public function __construct($id, $date, $userID)
 {
     $this->id = $id;
     $this->date = $date;
     $this->userID = $userID;
     $this->order_details = OrderDetail::find($id);
     $this->sum = $this->getSum();
 }
 /**
  * postEditModal
  */
 public function postEditModal()
 {
     $stockup = Input::get('stockup');
     $stockup = json_decode($stockup, true);
     $order_id = Input::get('order_id');
     $order = Order::find(Input::get('order_id'));
     //添加表
     $stock = new Stockup();
     $stock->order_id = $order_id;
     $stock->stockup_count = 0;
     $stock->item_count = 0;
     $stock->amount = 0.0;
     $stock->operator = '5';
     $stock->auditors = '4';
     $stock->save();
     //添加细表
     $stockup_count = $item_count = $amount = 0;
     foreach ($order->orderdetails as $orderdetail) {
         $confirm_quantity = 0;
         $ready_stock = $real_stock = 0;
         if ($stockup[$orderdetail->item->code]['stockup']) {
             foreach ($stockup[$orderdetail->item->code]['stockup'] as $value) {
                 //库存 有位置 identity status
                 if (isset($value['position']) && !empty($value['position'])) {
                     $stockdetail = new StockupDetail();
                     $stockdetail->stockup_id = $stock->id;
                     $stockdetail->identity = isset($value['item']) ? $value['item'] : '';
                     $stockdetail->supplier_id = 0;
                     $stockdetail->item_id = $orderdetail->item->id;
                     $stockdetail->quantity = $value['quantity'];
                     $stockdetail->position = $value['position'];
                     $stockdetail->status = 2;
                     $stockdetail->packaged = 0;
                     $stockdetail->save();
                     //位置减库存
                     $real_stock += $value['quantity'];
                     //预录入状态更新
                     if (isset($value['item'])) {
                         $item_detail = ItemReceivedPackageDetail::find($value['item']);
                         $item_detail->status = 3;
                         $item_detail->save();
                     }
                     //位置库存
                     $item_position = Warehouse::find($value['position']);
                     $item_position->quantity -= $value['quantity'];
                     $item_position->save();
                 } else {
                     //预录入 没有位置
                     $stockdetail = new StockupDetail();
                     $stockdetail->stockup_id = $stock->id;
                     $stockdetail->identity = $value['item'];
                     $stockdetail->supplier_id = '';
                     $stockdetail->item_id = $orderdetail->item->id;
                     $stockdetail->quantity = $value['quantity'];
                     $stockdetail->position = '';
                     $stockdetail->status = 1;
                     $stockdetail->packaged = 0;
                     $stockdetail->save();
                     $ready_stock += $value['quantity'];
                     //预录入状态更新
                     $item_detail = ItemReceivedPackageDetail::find($value['item']);
                     $item_detail->status = 3;
                     $item_detail->save();
                 }
                 $item_count++;
                 $stockup_count += $value['quantity'];
                 $confirm_quantity += $value['quantity'];
                 $amount += $value['quantity'] * $orderdetail->confirm_price;
                 //减状态
                 //减少库存
             }
         }
         //减少库存总数
         $item = Item::find($orderdetail->item->id);
         $item->stock -= $real_stock;
         $item->readystock -= $ready_stock;
         $item->save();
         //更新订单备货数量
         $detail = OrderDetail::find($orderdetail->id);
         $detail->confirm_quantity = $confirm_quantity;
         $detail->save();
     }
     //总计,匹数,米数,金额
     $stock->stockup_count = $stockup_count;
     $stock->item_count = $item_count;
     $stock->amount = $amount;
     $stock->save();
     //更新订单状态|应付款项合计
     $order->item_fee = $amount;
     $order->order_status = 'order_stockuped';
     $order->save();
     return Redirect::to('admin/stockups');
 }