public function editInventoryDetail()
    {
        $Re_Order_Level = Input::json('re_order_level') ? Input::json('re_order_level') : 'NULL';
        $LastCycleCount = Input::json('lastcyclecount') ? Input::json('lastcyclecount') : 'NULL';
        $LastAdjustmentCount = Input::json('lastadjustmentcount') ? Input::json('lastadjustmentcount') : 'NULL';
        $inventory_list = DB::select(DB::raw("SELECT * FROM `InventoryItems` WHERE Channel_Id=" . Input::json('channel') . " AND Warehouse_Id=" . Input::json('warehouse') . " AND Product_Id=" . Input::json('product')));
        $update_inventory_details = DB::select(DB::raw('UPDATE inventoryitems SET 
			Stock_Count =' . Input::json('add_quantity') . ' + ' . $inventory_list[0]->Stock_Count . ', 
			Re_Order_Level =' . $Re_Order_Level . ', Notes = ' . "'" . Input::json('notes') . "'" . ',
			LastCycleCount = ' . $LastCycleCount . ',LastAdjustmentCount = ' . $LastAdjustmentCount . ',
			Reason = ' . "'" . Input::json('reason') . "'" . ' where InventoryItem_Id = ' . Input::json('inventoryid')));
        $inv_log_dtl = new InventoryItemLog();
        $inv_log_dtl->InventoryItem_Id = Input::json('inventoryid');
        $inv_log_dtl->Product_Id = Input::json('product');
        $inv_log_dtl->Warehouse_Id = Input::json('warehouse');
        $inv_log_dtl->Channel_Id = Input::json('channel');
        $inv_log_dtl->Stock_Count = Input::json('add_quantity') + $inventory_list[0]->Stock_Count;
        $inv_log_dtl->Re_Order_Level = Input::json('re_order_level') ? Input::json('re_order_level') : null;
        $inv_log_dtl->Notes = Input::json('notes');
        $inv_log_dtl->Reason = Input::json('reason');
        $inv_log_dtl->LastCycleCount = Input::json('lastcyclecount') ? Input::json('lastcyclecount') : null;
        $inv_log_dtl->LastAdjustmentCount = Input::json('lastadjustmentcount') ? Input::json('lastadjustmentcount') : null;
        $inv_log_dtl->Active = 1;
        $inv_log_dtl->Create_ts = date("Y-m-d H:i:s");
        $inv_log_dtl->Modify_ts = date("Y-m-d H:i:s");
        $inv_log_dtl->save();
        return Response::json(array('response' => "Succesfully Updated!!!"));
    }
    public function editDirectShipmentDetails()
    {
        $old_shipment_item = Input::json('old_shipment_qty');
        $new_shipment_item = Input::json('shipment_qty');
        $result = array_diff($old_shipment_item, $new_shipment_item);
        if (count($result) == "0") {
            $update_job_details = DB::select(DB::raw('update jobs set `Job_Status_Id` =' . "'" . Input::json('status') . "'" . ' where Job_Id = ' . Input::json('jobid')));
            $update_shipment_details = DB::select(DB::raw('update shipments set `Date_Of_Shipment` =' . "'" . Input::json('date_of_shipment') . "'" . ',
				 `Warehouse_Name` =' . "'" . Input::json('warehouse') . "'" . ',
				 `TrackingNumber` =' . "'" . Input::json('tracking_number') . "'" . ',
				 `RecipientName` =' . "'" . Input::json('recipient_name') . "'" . ',
				 `ShipAddress1` =' . "'" . Input::json('shippingaddress') . "'" . ',
				 `ShipAddress2` =' . "'" . Input::json('shippingaddress2') . "'" . ',
				 `ShipCountry` =' . "'" . Input::json('shipcountry') . "'" . ',
				 `ShipState` =' . "'" . Input::json('shipstate') . "'" . ',
				 `ShipCity` =' . "'" . Input::json('shipcity') . "'" . ',
				 `ShipZip` =' . "'" . Input::json('shipzip') . "'" . ',
				 `ShipEmail` =' . "'" . Input::json('ship_email') . "'" . ',
				 `ShippingAccount` =' . "'" . Input::json('shipping_account') . "'" . ',
				 `TrackingNumber` =' . "'" . Input::json('tracking_number') . "'" . ',
				 `ShipmentCost` =' . "'" . Input::json('shipping_cost') . "'" . ',
				 `ActualShipmentCost` =' . "'" . Input::json('actual_shipment_cost') . "'" . ',
				 `Carrier_Id` =' . "'" . Input::json('carrier_name') . "'" . ',
				 `CarrierService_Id` =' . "'" . Input::json('carrier_service_name') . "'" . ',
				 `SignatureRequired` =' . "'" . Input::json('signature_required') . "'" . ',
				 `EmailNotification` =' . "'" . Input::json('email_notification') . "'" . ',
				 `AdditionalNotes` =' . "'" . Input::json('additional_notes') . "'" . '
				  where Shipment_Id = ' . Input::json('shipmentid')));
            return Response::json(array('response' => "Succesfully Updated!!!"));
        } else {
            $delete_shipment_box_details = DB::select(DB::raw('UPDATE ShipmentsBoxes SET `ACTIVE` = "0" WHERE Shipment_Id = ' . Input::json('shipmentid')));
            //$delete_shipment_box_item_details = DB::select(DB::raw('UPDATE ShipmentsBoxItems SET `ACTIVE` = "0" WHERE Shipment_Box_Id = ' . Input::json('shipment_box_id')));
            $update_job_details = DB::select(DB::raw('update jobs set `Job_Status_Id` =' . "'" . Input::json('status') . "'" . ' where Job_Id = ' . Input::json('jobid')));
            $update_shipment_details = DB::select(DB::raw('update shipments set `Date_Of_Shipment` =' . "'" . Input::json('date_of_shipment') . "'" . ',
			 `Warehouse_Name` =' . "'" . Input::json('warehouse') . "'" . ',
			 `TrackingNumber` =' . "'" . Input::json('tracking_number') . "'" . ',
			 `RecipientName` =' . "'" . Input::json('recipient_name') . "'" . ',
			 `ShipAddress1` =' . "'" . Input::json('shippingaddress') . "'" . ',
			 `ShipAddress2` =' . "'" . Input::json('shippingaddress2') . "'" . ',
			 `ShipCountry` =' . "'" . Input::json('shipcountry') . "'" . ',
			 `ShipState` =' . "'" . Input::json('shipstate') . "'" . ',
			 `ShipCity` =' . "'" . Input::json('shipcity') . "'" . ',
			 `ShipZip` =' . "'" . Input::json('shipzip') . "'" . ',
			 `ShipEmail` =' . "'" . Input::json('ship_email') . "'" . ',
			 `ShippingAccount` =' . "'" . Input::json('shipping_account') . "'" . ',
			 `TrackingNumber` =' . "'" . Input::json('tracking_number') . "'" . ',
			 `ShipmentCost` =' . "'" . Input::json('shipping_cost') . "'" . ',
			 `ActualShipmentCost` =' . "'" . Input::json('actual_shipment_cost') . "'" . ',
			 `Carrier_Id` =' . "'" . Input::json('carrier_name') . "'" . ',
			 `CarrierService_Id` =' . "'" . Input::json('carrier_service_name') . "'" . ',
			 `SignatureRequired` =' . "'" . Input::json('signature_required') . "'" . ',
			 `EmailNotification` =' . "'" . Input::json('email_notification') . "'" . ',
			 `AdditionalNotes` =' . "'" . Input::json('additional_notes') . "'" . '
			  where Shipment_Id = ' . Input::json('shipmentid')));
            $shipment_item_count = count(Input::json('order_item'));
            for ($i = 0; $i < $shipment_item_count; $i++) {
                if (Input::json('old_shipment_qty')['old_shipment_qty' . $i] > Input::json('shipment_qty')['shipment_qty' . $i]) {
                    $new_balance_qty = Input::json('old_shipment_qty')['old_shipment_qty' . $i] - Input::json('shipment_qty')['shipment_qty' . $i];
                    $new_balance_qty = Input::json('balance_qty')['balance_qty' . $i] + $new_balance_qty;
                    $update_shipment_item_details = DB::select(DB::raw('update ShipmentItems set `Shipment_Qty` = ' . "'" . Input::json('shipment_qty')['shipment_qty' . $i] . "'" . ' ,`Ship_Balance_Qty` =' . Input::json('shipment_qty')['shipment_qty' . $i] . ' where Shipment_Item_Id = ' . Input::json('shipment_item_id')['shipment_item_id' . $i]));
                    $order_balance_qty = Input::json('old_shipment_qty')['old_shipment_qty' . $i] - Input::json('shipment_qty')['shipment_qty' . $i];
                    $new_order_balance_qty = Input::json('old_balance_qty')['old_balance_qty' . $i] + $order_balance_qty;
                    $avilable_stock_counts = Input::json('avilable_stock_count')['avilable_stock_count' . $i] + $order_balance_qty;
                    $update_inv_stock_count = DB::select(DB::raw('update InventoryItems set `Stock_Count` =' . $avilable_stock_counts . ' where InventoryItem_Id = ' . Input::json('inv_item_id')['inv_item_id' . $i] . ' AND Channel_Id =' . Input::json('channel_name') . ' AND Warehouse_Id =' . Input::json('warehouse_id')));
                    if (isset(Input::json('inv_item_id')['inv_item_id' . $i])) {
                        $inv_log_dtl = new InventoryItemLog();
                        $inv_log_dtl->Job_Id = Input::json('jobid');
                        $inv_log_dtl->InventoryItem_Id = Input::json('inv_item_id')['inv_item_id' . $i];
                        $inv_id = Input::json('inv_item_id')['inv_item_id' . $i];
                        $inventory_ids = $this->getProdIdByInvID($inv_id);
                        $inv_log_dtl->Product_Id = $inventory_ids[0]->Product_Id;
                        $inv_log_dtl->Channel_Id = Input::json('channel_id');
                        $inv_log_dtl->Warehouse_Id = Input::json('warehouse_id');
                        $inv_log_dtl->Stock_Count = $avilable_stock_counts;
                        $inv_log_dtl->Re_Order_Level = "0";
                        $inv_log_dtl->Notes = "";
                        $inv_log_dtl->Reason = "";
                        $inv_log_dtl->LastCycleCount = "0";
                        $inv_log_dtl->LastAdjustmentCount = "0";
                        $inv_log_dtl->Active = 1;
                        $inv_log_dtl->Create_ts = date("Y-m-d H:i:s");
                        $inv_log_dtl->Modify_ts = date("Y-m-d H:i:s");
                        $inv_log_dtl->save();
                    }
                } else {
                    if (Input::json('old_shipment_qty')['old_shipment_qty' . $i] < Input::json('shipment_qty')['shipment_qty' . $i]) {
                        $new_balance_qty = Input::json('shipment_qty')['shipment_qty' . $i] - Input::json('old_shipment_qty')['old_shipment_qty' . $i];
                        $new_balance_qty = Input::json('balance_qty')['balance_qty' . $i] - $new_balance_qty;
                        $update_shipment_item_details = DB::select(DB::raw('update ShipmentItems set `Shipment_Qty` = ' . "'" . Input::json('shipment_qty')['shipment_qty' . $i] . "'" . ',`Ship_Balance_Qty` =' . Input::json('shipment_qty')['shipment_qty' . $i] . ' where Shipment_Item_Id = ' . Input::json('shipment_item_id')['shipment_item_id' . $i]));
                        $order_balance_qty = Input::json('old_shipment_qty')['old_shipment_qty' . $i] - Input::json('shipment_qty')['shipment_qty' . $i];
                        $new_order_balance_qty = Input::json('old_balance_qty')['old_balance_qty' . $i] + $order_balance_qty;
                        $avilable_stock_counts = Input::json('avilable_stock_count')['avilable_stock_count' . $i] + $order_balance_qty;
                        $update_inv_stock_count = DB::select(DB::raw('update InventoryItems set `Stock_Count` =' . $avilable_stock_counts . ' where InventoryItem_Id = ' . Input::json('inv_item_id')['inv_item_id' . $i] . ' AND Channel_Id =' . Input::json('channel_name') . ' AND Warehouse_Id =' . Input::json('warehouse_id')));
                        if (isset(Input::json('inv_item_id')['inv_item_id' . $i])) {
                            $inv_log_dtl = new InventoryItemLog();
                            $inv_log_dtl->Job_Id = Input::json('jobid');
                            $inv_log_dtl->InventoryItem_Id = Input::json('inv_item_id')['inv_item_id' . $i];
                            $inv_id = Input::json('inv_item_id')['inv_item_id' . $i];
                            $inventory_ids = $this->getProdIdByInvID($inv_id);
                            $inv_log_dtl->Product_Id = $inventory_ids[0]->Product_Id;
                            $inv_log_dtl->Channel_Id = Input::json('channel_id');
                            $inv_log_dtl->Warehouse_Id = Input::json('warehouse_id');
                            $inv_log_dtl->Stock_Count = $avilable_stock_counts;
                            $inv_log_dtl->Re_Order_Level = "0";
                            $inv_log_dtl->Notes = "";
                            $inv_log_dtl->Reason = "";
                            $inv_log_dtl->LastCycleCount = "0";
                            $inv_log_dtl->LastAdjustmentCount = "0";
                            $inv_log_dtl->Active = 1;
                            $inv_log_dtl->Create_ts = date("Y-m-d H:i:s");
                            $inv_log_dtl->Modify_ts = date("Y-m-d H:i:s");
                            $inv_log_dtl->save();
                        }
                    }
                }
            }
        }
    }