예제 #1
0
 public function postScan()
 {
     $in = Input::get();
     $code = $in['txtin'];
     $outlet_id = $in['outlet_id'];
     $use_outlet = $in['search_outlet'];
     $action = strtolower($in['action']);
     $session = $in['session'];
     $outlets = Prefs::getOutlet()->OutletToSelection('_id', 'name', false);
     $outlet_name = $outlets[$outlet_id];
     $res = 'OK';
     $msg = '';
     if (strripos($code, '|') >= 0) {
         $code = explode('|', $code);
         $SKU = $code[0];
         $unit_id = $code[1];
     } else {
         $SKU = trim($code);
         $unit_id = null;
     }
     switch ($action) {
         case 'add':
             if (is_null($unit_id)) {
                 $res = 'NOK';
                 $msg = 'SKU: ' . $SKU . ' <br />Unit ID: NOT FOUND';
                 break;
             }
             $u = Stockunit::where('SKU', '=', $SKU)->where('_id', 'like', '%' . $unit_id)->where('status', 'available')->first();
             if ($u) {
                 $ul = $u->toArray();
                 $ul['scancheckDate'] = new MongoDate();
                 $ul['createdDate'] = new MongoDate();
                 $ul['lastUpdate'] = new MongoDate();
                 $ul['action'] = $action;
                 $ul['status'] = 'reserved';
                 $ul['quantity'] = 1;
                 $ul['unitPrice'] = $ul['productDetail']['priceRegular'];
                 $ul['unitTotal'] = $ul['productDetail']['priceRegular'];
                 $ul['deliverTo'] = $outlet_name;
                 $ul['deliverToId'] = $outlet_id;
                 $ul['returnTo'] = $outlet_name;
                 $ul['returnToId'] = $outlet_id;
                 $ul['sessionId'] = $session;
                 $ul['sessionStatus'] = 'open';
                 $unit_id = $ul['_id'];
                 unset($ul['_id']);
                 $ul['unitId'] = $unit_id;
                 Transaction::insert($ul);
                 $history = array('datetime' => new MongoDate(), 'action' => 'pos', 'price' => $ul['productDetail']['priceRegular'], 'status' => $ul['status'], 'outletName' => $ul['outletName']);
                 //change status to sold
                 $u->status = 'reserved';
                 $u->push('history', $history);
                 $u->save();
                 $res = 'OK';
                 $msg = 'SKU: ' . $ul['SKU'] . ' <br />Unit ID: ' . $unit_id . ' <br />Outlet: ' . $ul['outletName'];
             } else {
                 $res = 'NOK';
                 $msg = 'SKU: ' . $SKU . ' <br />Unit ID: ' . $unit_id . ' <br />NOT FOUND in this outlet';
             }
             break;
         case 'remove':
             if (is_null($unit_id)) {
                 $res = 'NOK';
                 $msg = 'SKU: ' . $SKU . ' <br />Unit ID: NOT FOUND';
                 break;
             }
             $u = Stockunit::where('SKU', '=', $SKU)->where('_id', 'like', '%' . $unit_id)->first();
             if ($u) {
                 $ul = $u->toArray();
                 $ul['scancheckDate'] = new MongoDate();
                 $ul['createdDate'] = new MongoDate();
                 $ul['lastUpdate'] = new MongoDate();
                 $ul['action'] = $action;
                 $ul['deliverTo'] = $outlet_name;
                 $ul['deliverToId'] = $outlet_id;
                 $ul['returnTo'] = $outlet_name;
                 $ul['returnToId'] = $outlet_id;
                 $unit_id = $ul['_id'];
                 unset($ul['_id']);
                 $ul['unitId'] = $unit_id;
                 Stockunitlog::insert($ul);
                 $history = array('datetime' => new MongoDate(), 'action' => $action, 'price' => $ul['productDetail']['priceRegular'], 'status' => $ul['status'], 'outletName' => $ul['outletName']);
                 $u->push('history', $history);
                 $u->save();
                 $res = 'OK';
                 $msg = 'SKU: ' . $ul['SKU'] . ' <br />Unit ID: ' . $unit_id . ' <br />Outlet: ' . $ul['outletName'];
             } else {
                 $res = 'NOK';
                 $msg = 'SKU: ' . $SKU . ' <br />Unit ID: ' . $unit_id . ' <br />NOT FOUND in this outlet';
             }
             break;
         default:
             break;
     }
     $total_price = Transaction::where('sessionId', $session)->sum('unitPrice');
     $result = array('total_price' => $total_price, 'result' => $res, 'msg' => $msg);
     return Response::json($result);
 }
예제 #2
0
 public function postScancheck()
 {
     $in = Input::get();
     $code = $in['txtin'];
     $outlet_id = $in['outlet_id'];
     $use_outlet = $in['search_outlet'];
     $res = 'OK';
     if (strripos($code, '|')) {
         $code = explode('|', $code);
         $SKU = $code[0];
         $unit_id = $code[1];
         if ($use_outlet == 1) {
             $u = Stockunit::where('outletId', '=', $outlet_id)->where('SKU', '=', $SKU)->where('_id', 'like', '%' . $unit_id)->first();
         } else {
             $u = Stockunit::where('SKU', '=', $SKU)->where('_id', 'like', '%' . $unit_id)->first();
         }
         if ($u) {
             $ul = $u->toArray();
             $ul['scancheckDate'] = new MongoDate();
             $ul['createdDate'] = new MongoDate();
             $ul['lastUpdate'] = new MongoDate();
             $unit_id = $ul['_id'];
             unset($ul['_id']);
             $ul['unitId'] = $unit_id;
             Stockunitlog::insert($ul);
             $history = array('datetime' => new MongoDate(), 'action' => 'scan', 'price' => $ul['productDetail']['priceRegular'], 'status' => $ul['status'], 'outletName' => $ul['outletName']);
             $u->push('history', $history);
             $res = 'OK';
             $msg = 'SKU: ' . $ul['SKU'] . ' <br />Unit ID: ' . $unit_id . ' <br />Outlet: ' . $ul['outletName'];
         } else {
             $res = 'NOK';
             $msg = 'SKU: ' . $SKU . ' <br />Unit ID: ' . $unit_id . ' <br />NOT FOUND in this outlet';
         }
     } else {
         $SKU = trim($code);
         if ($use_outlet) {
             $u = Stockunit::where('outletId', '=', $outlet_id)->where('SKU', '=', $SKU)->first();
         } else {
             $u = Stockunit::where('SKU', '=', $SKU)->first();
         }
         if ($u) {
             $ul = $u->toArray();
             $ul['scancheckDate'] = new MongoDate();
             $ul['createdDate'] = new MongoDate();
             $ul['lastUpdate'] = new MongoDate();
             $unit_id = $ul['_id'];
             unset($ul['_id']);
             $ul['unitId'] = $unit_id;
             Stockunitlog::insert($ul);
             $history = array('datetime' => new MongoDate(), 'action' => 'scan', 'price' => $ul['productDetail']['priceRegular'], 'status' => $ul['status'], 'outletName' => $ul['outletName']);
             $u->push('history', $history);
             $res = 'OK';
             $msg = 'SKU: ' . $ul['SKU'] . ' <br />Unit ID: ' . $unit_id . ' <br />Outlet: ' . $ul['outletName'];
         } else {
             $res = 'NOK';
             $msg = 'SKU: ' . $SKU . ' <br />Unit ID: ' . $unit_id . ' <br />NOT FOUND in this outlet';
         }
     }
     $result = array('result' => $res, 'msg' => $msg);
     return Response::json($result);
 }