public HttpResponseMessage Post([FromBody] GrnModel grnModel) { try { if (string.IsNullOrEmpty(grnModel.GrnMasterData.company_id.ToString())) { var formatter = RequestFormat.JsonFormaterString(); return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation { output = "error", msg = "Please Select Company !!" }, formatter)); } if (string.IsNullOrEmpty(grnModel.GrnMasterData.supplier_id.ToString())) { var formatter = RequestFormat.JsonFormaterString(); return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation { output = "error", msg = "Please Select Supplier !!" }, formatter)); } if (string.IsNullOrEmpty(grnModel.GrnMasterData.purchase_order_master_id.ToString())) { var formatter = RequestFormat.JsonFormaterString(); return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation { output = "error", msg = "Please Select Purchase Order !!" }, formatter)); } if (string.IsNullOrEmpty(grnModel.GrnMasterData.warehouse_id.ToString())) { var formatter = RequestFormat.JsonFormaterString(); return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation { output = "error", msg = "Please Select Warehouse !!" }, formatter)); } else { var x = _grnRepository.AddGrn(grnModel); if (x == 1) { var formatter = RequestFormat.JsonFormaterString(); return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation { output = "success", msg = "Grn save successfully" }, formatter)); } else { var formatter = RequestFormat.JsonFormaterString(); return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation { output = "error", msg = "Duplicate IMEI Found !!!" }, formatter)); } } } catch (Exception ex) { var formatter = RequestFormat.JsonFormaterString(); return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation { output = "error", msg = ex.ToString() }, formatter)); } }
public bool EditGrn(GrnModel grnModel) { throw new NotImplementedException(); }
public long AddGrn(GrnModel grnModel) { try { var grnMaster = grnModel.GrnMasterData; var grnDetailsList = grnModel.GrnDetailsList; var receiveSerialNoDetails = grnModel.ReceiveSerialNoDetails; bool isDuplicateImei = false; foreach (var item in receiveSerialNoDetails) { long imeiForDuplicateSearch = item.imei_no ?? 0; var xxx = _entities.receive_serial_no_details.Where(r => r.imei_no == imeiForDuplicateSearch).ToList(); if (xxx.Count > 0) { isDuplicateImei = true; } } if (!isDuplicateImei) { // generate order_no long grnSerial = _entities.grn_master.Max(po => (long?)po.grn_master_id) ?? 0; grnSerial++; var grnStr = grnSerial.ToString().PadLeft(7, '0'); // SAVING GRN MASTER string grnNo = "GRN-" + grnStr; grnMaster.supplier_id = grnModel.GrnMasterData.supplier_id; grnMaster.total_amount_including_vattax = grnModel.GrnMasterData.total_amount_including_vattax; grnMaster.status = grnModel.GrnMasterData.status; grnMaster.company_id = grnModel.GrnMasterData.company_id; grnMaster.grn_date = grnModel.GrnMasterData.grn_date; grnMaster.purchase_order_master_id = grnModel.GrnMasterData.purchase_order_master_id; grnMaster.vat_total = grnModel.GrnMasterData.vat_total; grnMaster.warehouse_id = grnModel.GrnMasterData.warehouse_id; grnMaster.created_by = grnModel.GrnMasterData.created_by; grnMaster.created_date = DateTime.Now; grnMaster.updated_by = grnModel.GrnMasterData.updated_by; grnMaster.updated_date = DateTime.Now; grnMaster.remarks = grnModel.GrnMasterData.remarks; grnMaster.lot_no = grnModel.GrnMasterData.lot_no; grnMaster.lc_id = 0; grnMaster.grn_no = grnNo; grnMaster.tax_total = grnModel.GrnMasterData.tax_total; grnMaster.total_amount_without_vattax = grnModel.GrnMasterData.total_amount_without_vattax; grnMaster.mrr_status = false; _entities.grn_master.Add(grnMaster); _entities.SaveChanges(); // Maruf: 28.Feb.2016: Update CiPl received = true //var ciPlMaster = _entities.ci_pl_master.Find(grnModel.GrnMasterData.purchase_order_master_id); var ciPlMaster = _entities.ci_pl_master.FirstOrDefault(c => c.purchase_order_master_id == grnModel.GrnMasterData.purchase_order_master_id); ciPlMaster.is_received = true; _entities.SaveChanges(); long grnMasterId = grnMaster.grn_master_id; foreach (var item in grnDetailsList) { var grnDetails = new grn_details { product_id = item.product_id, grn_master_id = grnMasterId, unit_id = item.unit_id, unit_price = item.unit_price, pi_quantity = item.pi_quantity, amount = item.amount, brand_id = item.brand_id, color_id = item.color_id, product_version_id = item.product_version_id, receive_quantity = item.receive_quantity, vat_amount = item.vat_amount, tax_amount = item.tax_amount, line_total = item.line_total, size_id = item.size_id, vat_pcnt = item.vat_pcnt, tax_pcnt = item.tax_pcnt }; _entities.grn_details.Add(grnDetails); // _entities.SaveChanges(); // kiron 04.09.2016 long saved = _entities.SaveChanges(); if (saved > 0) { // update inventory InventoryRepository updateInventoty = new InventoryRepository(); // Maruf: 04.Apr.2017: move product from purchase(29) WH to GRN(4) WH; it will move to central after MRR process updateInventoty.UpdateInventory("GRN", grnMaster.grn_no, 29, 4, grnDetails.product_id ?? 0, grnDetails.color_id ?? 0, grnDetails.product_version_id ?? 0, grnDetails.unit_id ?? 0, grnDetails.receive_quantity ?? 0, grnMaster.created_by ?? 0); } long purchaseOrderDetailsId = item.purchase_order_details_id; purchase_order_details poDetails = _entities.purchase_order_details.Find(purchaseOrderDetailsId); poDetails.receive_qty += item.receive_quantity; _entities.SaveChanges(); } foreach (var item in receiveSerialNoDetails) { int c = 0; var receiveSerialNoDetailsData = new receive_serial_no_details { product_id = item.product_id, grn_master_id = grnMasterId, brand_id = item.brand_id, color_id = item.color_id, product_version_id = item.product_version_id, imei_no = item.imei_no, imei_no2 = item.imei_no2, received_warehouse_id = 4, // 4-GRN WH; will be moved to central after MRR current_warehouse_id = 4, // 4-GRN WH; will be moved to central after MRR received_date = item.received_date, requisition_id = 0, deliver_master_id = 0, sales_status = false, price_protected = false, carton_no = item.carton_no }; _entities.receive_serial_no_details.Add(receiveSerialNoDetailsData); c++; if (c == 100) { c = 0; _entities.SaveChanges(); } } _entities.SaveChanges(); return(1); } return(0); } catch (Exception) { return(0); } }