private void PurchaseReturn_Sync() { //remember to clean out those that are already accounted from SalesSync. //entity.DebeHaber.Transactions Transactions = new entity.DebeHaber.Transactions(); entity.DebeHaber.Transactions PurchaseReturnError = new entity.DebeHaber.Transactions(); //Loop through foreach (entity.purchase_return purchase_return in db.purchase_return.Local.Where(x => x.IsSelected && x.is_accounted == false)) { entity.DebeHaber.Transactions Transactions = new entity.DebeHaber.Transactions(); Transactions.HashIntegration = RelationshipHash; entity.DebeHaber.Commercial_Invoice PurchaseReturn = new entity.DebeHaber.Commercial_Invoice(); //Loads Data from Sales PurchaseReturn.Fill_ByPurchaseReturn(purchase_return); ///Loop through Details. foreach (entity.purchase_return_detail Detail in purchase_return.purchase_return_detail) { entity.DebeHaber.CommercialInvoice_Detail CommercialInvoice_Detail = new entity.DebeHaber.CommercialInvoice_Detail(); //Fill and Detail SalesDetail CommercialInvoice_Detail.Fill_ByPurchaseReturn(Detail, db); PurchaseReturn.CommercialInvoice_Detail.Add(CommercialInvoice_Detail); } //Loop through payments made. foreach (entity.payment_schedual schedual in purchase_return.payment_schedual) { if (schedual.payment_detail != null && schedual.payment_detail.payment.is_accounted == false) { entity.DebeHaber.Payments Payments = new entity.DebeHaber.Payments(); //Fill and Add Payments Payments.FillPayments(schedual); PurchaseReturn.Payments.Add(Payments); //This will make the Sales Invoice hide from the next load. schedual.payment_detail.payment.is_accounted = true; } } Transactions.Commercial_Invoice.Add(PurchaseReturn); try { var Json = new JavaScriptSerializer().Serialize(Transactions); Send2API(Json); purchase_return.is_accounted = true; } catch (Exception) { PurchaseReturnError.Commercial_Invoice.Add(PurchaseReturn); purchase_return.is_accounted = false; } finally { db.SaveChanges(); } } }
private void Sales_Sync() { //entity.DebeHaber.Transactions Transactions = new entity.DebeHaber.Transactions(); entity.DebeHaber.Transactions SalesError = new entity.DebeHaber.Transactions(); //Loop through foreach (entity.sales_invoice sales_invoice in db.sales_invoice.Local.Where(x => x.IsSelected))// && x.is_accounted == false)) { entity.DebeHaber.Transactions Transactions = new entity.DebeHaber.Transactions(); Transactions.HashIntegration = RelationshipHash; entity.DebeHaber.Commercial_Invoice Sales = new entity.DebeHaber.Commercial_Invoice(); //Loads Data from Sales Sales.Fill_BySales(sales_invoice); ///Loop through Details. foreach (entity.sales_invoice_detail Detail in sales_invoice.sales_invoice_detail) { entity.DebeHaber.CommercialInvoice_Detail CommercialInvoice_Detail = new entity.DebeHaber.CommercialInvoice_Detail(); //Fill and Detail SalesDetail CommercialInvoice_Detail.Fill_BySales(Detail, db); Sales.CommercialInvoice_Detail.Add(CommercialInvoice_Detail); } //Loop through payments made. foreach (entity.payment_schedual schedual in sales_invoice.payment_schedual) { if (schedual.payment_detail != null && schedual.payment_detail.payment.is_accounted == false) { entity.DebeHaber.Payments Payments = new entity.DebeHaber.Payments(); //Fill and Add Payments Payments.FillPayments(schedual); Sales.Payments.Add(Payments); //This will make the Sales Invoice hide from the next load. schedual.payment_detail.payment.is_accounted = true; } } Transactions.Commercial_Invoice.Add(Sales); try { var Sales_Json = new JavaScriptSerializer().Serialize(Transactions); Send2API(Sales_Json); sales_invoice.is_accounted = true; } catch (Exception) { SalesError.Commercial_Invoice.Add(Sales); sales_invoice.is_accounted = false; } finally { db.SaveChanges(); } } }