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(); } } }
private void FixedAsset() { //entity.DebeHaber.Transactions Transactions = new entity.DebeHaber.Transactions(); entity.DebeHaber.Transactions FixedAssetError = new entity.DebeHaber.Transactions(); foreach (entity.item_asset_group item_asset_group in db.item_asset_group.Where(x => x.id_company == entity.CurrentSession.Id_Company).ToList()) { entity.DebeHaber.Transactions Transactions = new entity.DebeHaber.Transactions(); Transactions.HashIntegration = RelationshipHash; entity.DebeHaber.FixedAssetGroup FixedAssetGroup = new entity.DebeHaber.FixedAssetGroup(); FixedAssetGroup.Name = item_asset_group.name; FixedAssetGroup.LifespanYears = (decimal)item_asset_group.depreciation_rate; //Loop through foreach (entity.item_asset item_asset in item_asset_group.item_asset.Where(x => x.IsSelected)) { entity.DebeHaber.FixedAsset FixedAsset = new entity.DebeHaber.FixedAsset(); FixedAsset.Name = item_asset.item.name; FixedAsset.Code = item_asset.item.code; FixedAsset.CurrentCost = (decimal)item_asset.current_value; FixedAsset.PurchaseCost = (decimal)item_asset.purchase_value; FixedAsset.PurchaseDate = (DateTime)item_asset.purchase_date; FixedAsset.Quantity = 1; FixedAsset.CurrencyName = entity.CurrentSession.Currency_Default.name; FixedAssetGroup.FixedAssets.Add(FixedAsset); } Transactions.FixedAssetGroup.Add(FixedAssetGroup); try { var Json = new JavaScriptSerializer().Serialize(Transactions); Send2API(Json); //payments.is_accounted = true; } catch (Exception) { //payments.is_accounted = false; } finally { db.SaveChanges(); } } }
private void PaymentSync() { //entity.DebeHaber.Transactions Transactions = new entity.DebeHaber.Transactions(); entity.DebeHaber.Transactions PaymentError = new entity.DebeHaber.Transactions(); //Loop through foreach (entity.payment payments in db.payments.Local.Where(x => x.IsSelected && x.is_accounted == false)) { entity.DebeHaber.Transactions Transactions = new entity.DebeHaber.Transactions(); Transactions.HashIntegration = RelationshipHash; foreach (entity.payment_detail payment_detail in payments.payment_detail.ToList()) { entity.DebeHaber.Payments Payment = new entity.DebeHaber.Payments(); //Loads Data from Sales entity.payment_schedual schedual = db.payment_schedual.Where(x => x.id_payment_detail == payment_detail.id_payment_detail).FirstOrDefault(); Payment.FillPayments(schedual); Transactions.Payments.Add(Payment); } try { var Json = new JavaScriptSerializer().Serialize(Transactions); Send2API(Json); payments.is_accounted = true; } catch (Exception) { payments.is_accounted = false; } finally { db.SaveChanges(); } } }