private void salesreturnComboBox_MouseDoubleClick(object sender, MouseButtonEventArgs e) { try { if (salesreturnComboBox.Data != null) { CollectionViewSource paymentpayment_detailViewSource = (CollectionViewSource)this.FindResource("paymentpayment_detailViewSource"); payment_detail payment_detail = paymentpayment_detailViewSource.View.CurrentItem as payment_detail; sales_return sales_return = (sales_return)salesreturnComboBox.Data; salesreturnComboBox.Text = sales_return.number; decimal return_value = (sales_return.GrandTotal - sales_return.payment_schedual.Where(x => x.id_sales_return == sales_return.id_sales_return).Sum(x => x.credit)); payment_detail.id_sales_return = sales_return.id_sales_return; if (payment_detail.value > return_value) { payment_detail.value = return_value; payment_detail.RaisePropertyChanged("value"); } else { payment_detail.value = payment_detail.value; payment_detail.RaisePropertyChanged("value"); } } } catch (Exception ex) { throw ex; } }
private void btnAddDetail_Click(object sender, RoutedEventArgs e) { payment payment = paymentViewSource.View.CurrentItem as payment; payment_detail payment_detailold = paymentpayment_detailViewSource.View.CurrentItem as payment_detail; payment_detail payment_detail = new payment_detail(); payment_detail.payment = payment; payment_detail.value = 0; int id_currencyfx = payment_detailold.payment_schedual.FirstOrDefault().id_currencyfx; if (PaymentDB.app_currencyfx.Where(x => x.id_currencyfx == id_currencyfx).FirstOrDefault() != null) { payment_detail.id_currencyfx = id_currencyfx; payment_detail.app_currencyfx = PaymentDB.app_currencyfx.Where(x => x.id_currencyfx == id_currencyfx).FirstOrDefault(); } int id_payment_schedual = payment_detailold.payment_schedual.FirstOrDefault().id_payment_schedual; if (PaymentDB.payment_schedual.Where(x => x.id_payment_schedual == id_payment_schedual).FirstOrDefault() != null) { payment_schedual _payment_schedual = PaymentDB.payment_schedual.Where(x => x.id_payment_schedual == id_payment_schedual).FirstOrDefault(); payment_detail.payment_schedual.Add(_payment_schedual); } payment.payment_detail.Add(payment_detail); paymentpayment_detailViewSource.View.Refresh(); }
private void NewPayment_MouseUp(object sender, MouseButtonEventArgs e) { payment payment = paymentViewSource.View.CurrentItem as payment; payment_detail payment_detail = new payment_detail(); payment.payment_detail.Add(payment_detail); }
public PaymentApproval(ref PaymentDB PaymentDB, List <payment_schedual> SchedualList) { PaymentDBold = PaymentDB; InitializeComponent(); //Setting the Mode for this Window. Result of this variable will determine logic of the certain Behaviours. payment_schedualViewSource = (CollectionViewSource)this.FindResource("payment_schedualViewSource"); paymentpayment_detailViewSource = (CollectionViewSource)this.FindResource("paymentpayment_detailViewSource"); payment_schedualViewSource.Source = PaymentDBold.payment_schedual.Local; payment_schedualViewSource.View.MoveCurrentTo(SchedualList.FirstOrDefault()); foreach (payment_schedual payment_schedual in SchedualList) { payment_detail payment_detail = new payment_detail(); payment_detail.value = SchedualList.Sum(x => x.AccountPayableBalance); payment_detail.IsSelected = true; payment_detail.id_currencyfx = SchedualList.FirstOrDefault().id_currencyfx; payment_detail.State = EntityState.Added; PaymentDBold.payment_detail.Add(payment_detail); payment_detail.payment_schedual.Add(payment_schedual); } paymentpayment_detailViewSource.Source = PaymentDBold.payment_detail.Local; paymentpayment_detailViewSource.View.MoveCurrentToFirst(); }
private void btnDeleteDetail_Click(object sender, RoutedEventArgs e) { payment payment = paymentViewSource.View.CurrentItem as payment; payment_detail payment_detail = paymentpayment_detailViewSource.View.CurrentItem as payment_detail; payment.payment_detail.Remove(payment_detail); paymentpayment_detailViewSource.View.Refresh(); }
private void dgvPaymentDetail_InitializingNewItem(object sender, InitializingNewItemEventArgs e) { sales_invoice sales_invoice = sales_invoiceViewSource.View.CurrentItem as sales_invoice; payment payment = paymentViewSource.View.CurrentItem as payment; payment_detail payment_detail = e.NewItem as payment_detail; payment_detail.State = EntityState.Added; payment_detail.IsSelected = true; payment_detail.id_currencyfx = sales_invoice.id_currencyfx; payment_detail.id_currency = sales_invoice.app_currencyfx.id_currency; payment_detail.id_payment = payment.id_payment; payment_detail.payment = payment; }
void filter_payment_detail() { if (paymentpayment_detailViewSource != null) { if (paymentpayment_detailViewSource.View != null) { paymentpayment_detailViewSource.View.Filter = i => { payment_detail payment_detail = (payment_detail)i; if (payment_detail.id_payment_detail == _id_payment_detail) { return(true); } else { return(false); } }; } } }
public void ReceivePayment(ref dbContext _entity, payment_schedual payment_schedual, int id_range, int id_currencyfx, int id_payment_type, int id_purchase_return, int id_sales_return, decimal value, string comment, int id_account, DateTime trans_date) { payment payment = new payment(); if (id_sales_return > 0) { payment.id_contact = payment_schedual.contact.id_contact; if (id_range != null) { payment.id_range = id_range; if (_entity.db.app_document_range.Where(x => x.id_range == payment.id_range).FirstOrDefault() != null) { payment.app_document_range = _entity.db.app_document_range.Where(x => x.id_range == payment.id_range).FirstOrDefault(); } } payment_detail payment_detailreturn = new payment_detail(); if (_entity.db.app_currencyfx.Where(x => x.id_currencyfx == id_currencyfx).FirstOrDefault() != null) { payment_detailreturn.app_currencyfx = _entity.db.app_currencyfx.Where(x => x.id_currencyfx == id_currencyfx).FirstOrDefault(); } payment_detailreturn.id_currencyfx = id_currencyfx; payment_detailreturn.id_payment_type = id_payment_type; payment_detailreturn.id_purchase_return = id_purchase_return; payment_detailreturn.id_sales_return = id_sales_return; payment_detailreturn.value = value; payment_detailreturn.comment = comment; payment_schedual _payment_schedualreturn = new payment_schedual(); _payment_schedualreturn.credit = Convert.ToDecimal(value); _payment_schedualreturn.parent = payment_schedual; _payment_schedualreturn.expire_date = payment_schedual.expire_date; _payment_schedualreturn.status = payment_schedual.status; _payment_schedualreturn.id_contact = payment_schedual.id_contact; _payment_schedualreturn.id_currencyfx = payment_schedual.id_currencyfx; _payment_schedualreturn.id_purchase_invoice = payment_schedual.id_purchase_invoice; _payment_schedualreturn.id_purchase_order = payment_schedual.id_purchase_order; _payment_schedualreturn.id_purchase_return = payment_schedual.id_purchase_return; _payment_schedualreturn.id_sales_invoice = payment_schedual.id_sales_invoice; _payment_schedualreturn.id_sales_order = payment_schedual.id_sales_order; _payment_schedualreturn.id_sales_return = id_sales_return; _payment_schedualreturn.trans_date = trans_date; payment_detailreturn.payment_schedual.Add(_payment_schedualreturn); payment.payment_detail.Add(payment_detailreturn); } else { payment.id_contact = payment_schedual.contact.id_contact; if (id_range > 0) { payment.id_range = id_range; if (_entity.db.app_document_range.Where(x => x.id_range == payment.id_range).FirstOrDefault() != null) { payment.app_document_range = _entity.db.app_document_range.Where(x => x.id_range == payment.id_range).FirstOrDefault(); } } payment_detail payment_detail = new payment_detail(); payment_detail.id_account = id_account; if (_entity.db.app_currencyfx.Where(x => x.id_currencyfx == id_currencyfx).FirstOrDefault() != null) { payment_detail.app_currencyfx = _entity.db.app_currencyfx.Where(x => x.id_currencyfx == id_currencyfx).FirstOrDefault(); } payment_detail.id_currencyfx = id_currencyfx; payment_detail.id_payment_type = id_payment_type; payment_detail.id_purchase_return = id_purchase_return; payment_detail.id_sales_return = id_sales_return; payment_detail.value = value; payment_detail.comment = comment; payment_schedual _payment_schedual = new payment_schedual(); _payment_schedual.credit = Convert.ToDecimal(value); _payment_schedual.parent = payment_schedual; _payment_schedual.expire_date = payment_schedual.expire_date; _payment_schedual.status = payment_schedual.status; _payment_schedual.id_contact = payment_schedual.id_contact; _payment_schedual.id_currencyfx = payment_schedual.id_currencyfx; _payment_schedual.id_purchase_invoice = payment_schedual.id_purchase_invoice; _payment_schedual.id_purchase_order = payment_schedual.id_purchase_order; _payment_schedual.id_purchase_return = payment_schedual.id_purchase_return; _payment_schedual.id_sales_invoice = payment_schedual.id_sales_invoice; _payment_schedual.id_sales_order = payment_schedual.id_sales_order; _payment_schedual.id_sales_return = payment_schedual.id_sales_return; _payment_schedual.trans_date = trans_date; payment_detail.payment_schedual.Add(_payment_schedual); payment.payment_detail.Add(payment_detail); //Add Account Logic. With IF FUnction if payment type is Basic Behaviour. If not ignore. if (_entity.db.payment_type.Where(x => x.id_payment_type == id_payment_type).FirstOrDefault().payment_behavior == payment_type.payment_behaviours.Normal) { app_account_detail app_account_detail = new app_account_detail(); if (_entity.db.app_account_session.Where(x => x.id_account == id_account && x.is_active).FirstOrDefault() != null) { app_account_detail.id_session = _entity.db.app_account_session.Where(x => x.id_account == id_account && x.is_active).FirstOrDefault().id_session; } app_account_detail.id_account = id_account; app_account_detail.id_currencyfx = payment_detail.id_currencyfx; app_account_detail.id_payment_type = id_payment_type; app_account_detail.trans_date = trans_date; app_account_detail.debit = 0; app_account_detail.credit = Convert.ToDecimal(value); _entity.db.app_account_detail.Add(app_account_detail); } } _entity.db.payments.Add(payment); IEnumerable <DbEntityValidationResult> validationresult = _entity.db.GetValidationErrors(); if (validationresult.Count() == 0) { _entity.SaveChanges(); entity.Brillo.Document.Start.Automatic(payment, payment.app_document_range); } }
private void cbxPamentType_SelectionChanged(object sender, SelectionChangedEventArgs e) { payment payment = paymentViewSource.View.CurrentItem as payment; if (cbxPamentType.SelectedItem != null) { entity.payment_type payment_type = cbxPamentType.SelectedItem as entity.payment_type; if (payment_type != null) { if (payment_type.payment_behavior == global::entity.payment_type.payment_behaviours.WithHoldingVAT) { //If payment behaviour is WithHoldingVAT, hide everything. stpaccount.Visibility = Visibility.Collapsed; stpcreditpurchase.Visibility = Visibility.Collapsed; stpcreditsales.Visibility = Visibility.Collapsed; } else if (payment_type.payment_behavior == global::entity.payment_type.payment_behaviours.CreditNote) { //If payment behaviour is Credit Note, then hide Account. stpaccount.Visibility = Visibility.Collapsed; //Check Mode. if (Mode == Modes.Payable) { //If Payable, then Hide->Sales and Show->Payment stpcreditsales.Visibility = Visibility.Collapsed; stpcreditpurchase.Visibility = Visibility.Visible; CollectionViewSource purchase_returnViewSource = this.FindResource("purchase_returnViewSource") as CollectionViewSource; PaymentDB.purchase_return.Where(x => x.id_contact == payment.id_contact).Load(); purchase_returnViewSource.Source = PaymentDB.purchase_return.Local; } else { //If Recievable, then Hide->Payment and Show->Sales stpcreditpurchase.Visibility = Visibility.Collapsed; stpcreditsales.Visibility = Visibility.Visible; CollectionViewSource sales_returnViewSource = this.FindResource("sales_returnViewSource") as CollectionViewSource; PaymentDB.sales_return.Where(x => x.id_contact == payment.id_contact && (x.sales_invoice.GrandTotal - x.GrandTotal) > 0).Load(); sales_returnViewSource.Source = PaymentDB.sales_return.Local; } } else { //If paymentbehaviour is not WithHoldingVAT & CreditNote, it must be Normal, so only show Account. stpaccount.Visibility = Visibility.Visible; stpcreditpurchase.Visibility = Visibility.Collapsed; stpcreditsales.Visibility = Visibility.Collapsed; } //If PaymentType has Document to print, then show Document. Example, Checks or Bank Transfers. if (payment_type.id_document > 0 && paymentpayment_detailViewSource != null && paymentpayment_detailViewSource.View != null) { stpDetailDocument.Visibility = Visibility.Visible; payment_detail payment_detail = paymentpayment_detailViewSource.View.CurrentItem as payment_detail; payment_detail.id_range = PaymentDB.app_document_range.Where(d => d.id_document == payment_type.id_document && d.is_active == true).Include(i => i.app_document).FirstOrDefault().id_range; } else { stpDetailDocument.Visibility = Visibility.Collapsed; } } } }
private void dgvPaymentDetail_SelectionChanged(object sender, SelectionChangedEventArgs e) { payment_detail payment_detail = paymentpayment_detailViewSource.View.CurrentItem as payment_detail; paymentpayment_detailViewSource.View.MoveCurrentTo(payment_detail); }
private void btnSave_Click(object sender, RoutedEventArgs e) { if (purchase_invoice != null) { if (dbContext.db.payment_schedual.Where(a => a.id_purchase_invoice == purchase_invoice.id_purchase_invoice && a.id_contact == purchase_invoice.id_contact).FirstOrDefault() != null) { payment_schedual payment_schedual = dbContext.db.payment_schedual.Where(a => a.id_purchase_invoice == purchase_invoice.id_purchase_invoice && a.id_contact == purchase_invoice.id_contact).FirstOrDefault(); if (invoice_total > 0) { payment_detail payment_detail = new payment_detail(); payment_detail.value = invoice_total; payment_detail.id_account = (int)app_accountComboBox.SelectedValue; payment payment = new payment(); if (payment_schedual != null) { payment.id_contact = payment_schedual.id_contact; payment.contact = payment_schedual.contact; payment_detail.id_currencyfx = payment_schedual.id_currencyfx; if (dbContext.db.payment_type.Where(x => x.is_default).FirstOrDefault() != null) { payment_detail.id_payment_type = dbContext.db.payment_type.Where(x => x.is_default).FirstOrDefault().id_payment_type; } else { MessageBox.Show("Please insert paymnent Type"); return; } } payment_detail.App_Name = global::entity.App.Names.PurchaseInvoice; payment_schedual _payment_schedual = new payment_schedual(); _payment_schedual.debit = invoice_total; _payment_schedual.parent = payment_schedual; _payment_schedual.expire_date = payment_schedual.expire_date; _payment_schedual.status = payment_schedual.status; _payment_schedual.id_contact = payment_schedual.id_contact; _payment_schedual.id_currencyfx = payment_schedual.id_currencyfx; _payment_schedual.id_purchase_invoice = payment_schedual.id_purchase_invoice; _payment_schedual.trans_date = DateTime.Now; _payment_schedual.AccountReceivableBalance = invoice_total; payment_detail.payment_schedual.Add(_payment_schedual); payment.payment_detail.Add(payment_detail); //Add Account Logic. With IF FUnction if payment type is Basic Behaviour. If not ignore. app_account_detail app_account_detail = new app_account_detail(); if (dbContext.db.app_account_session.Where(x => x.id_account == payment_detail.id_account && x.is_active).FirstOrDefault() != null) { app_account_detail.id_session = dbContext.db.app_account_session.Where(x => x.id_account == payment_detail.id_account && x.is_active).FirstOrDefault().id_session; } app_account_detail.id_account = (int)payment_detail.id_account; app_account_detail.id_currencyfx = payment_schedual.id_currencyfx; app_account_detail.id_payment_type = payment_detail.id_payment_type; app_account_detail.debit = Convert.ToDecimal(payment_detail.value); app_account_detail.credit = 0; dbContext.db.app_account_detail.Add(app_account_detail); dbContext.db.payments.Add(payment); IEnumerable <DbEntityValidationResult> validationresult = dbContext.db.GetValidationErrors(); if (validationresult.Count() == 0) { dbContext.db.SaveChanges(); entity.Brillo.Logic.Document Document = new entity.Brillo.Logic.Document(); Document.Document_PrintPaymentReceipt(payment); imgCancel_MouseDown(null, null); } } } else { MessageBox.Show("Please Save and Approve invoice first to Make Payment.", "Cognitivo", MessageBoxButton.OK, MessageBoxImage.Asterisk); } } if (sales_invoice != null) { PaymentDB PaymentDB = new entity.PaymentDB(); if (PaymentDB.payment_schedual.Where(a => a.id_sales_invoice == sales_invoice.id_sales_invoice && a.id_contact == sales_invoice.id_contact).FirstOrDefault() != null) { payment_schedual payment_schedual = PaymentDB.payment_schedual.Where(a => a.id_sales_invoice == sales_invoice.id_sales_invoice && a.id_contact == sales_invoice.id_contact).FirstOrDefault(); if (invoice_total > 0) { payment_detail payment_detail = new payment_detail(); payment_detail.value = invoice_total; payment_detail.id_account = (int)app_accountComboBox.SelectedValue; payment payment = new payment(); if (payment_schedual != null) { payment.id_contact = payment_schedual.id_contact; payment.contact = payment_schedual.contact; payment_detail.id_currencyfx = payment_schedual.id_currencyfx; if (PaymentDB.payment_type.Where(x => x.is_default).FirstOrDefault() != null) { payment_detail.id_payment_type = PaymentDB.payment_type.Where(x => x.is_default).FirstOrDefault().id_payment_type; } else { MessageBox.Show("Please insert paymnent Type"); return; } } payment_detail.IsSelected = true; payment_detail.App_Name = global::entity.App.Names.SalesInvoice; payment.payment_detail.Add(payment_detail); //payment_schedual _payment_schedual = new payment_schedual(); //_payment_schedual.credit = invoice_total; //_payment_schedual.parent = payment_schedual; //_payment_schedual.expire_date = payment_schedual.expire_date; //_payment_schedual.status = payment_schedual.status; //_payment_schedual.id_contact = payment_schedual.id_contact; //_payment_schedual.id_currencyfx = payment_schedual.id_currencyfx; //_payment_schedual.id_sales_invoice = payment_schedual.id_sales_invoice; //_payment_schedual.trans_date = payment_schedual.trans_date; //_payment_schedual.AccountReceivableBalance = invoice_total; //payment_detail.payment_schedual.Add(_payment_schedual); //payment.payment_detail.Add(payment_detail); ////Add Account Logic. With IF FUnction if payment type is Basic Behaviour. If not ignore. //app_account_detail app_account_detail = new app_account_detail(); //if (dbContext.db.app_account_session.Where(x => x.id_account == payment_detail.id_account && x.is_active).FirstOrDefault() != null) //{ // app_account_detail.id_session = dbContext.db.app_account_session.Where(x => x.id_account == payment_detail.id_account && x.is_active).FirstOrDefault().id_session; //} //app_account_detail.id_account = (int)payment_detail.id_account; //app_account_detail.id_currencyfx = payment_schedual.id_currencyfx; //app_account_detail.id_payment_type = payment_detail.id_payment_type; //app_account_detail.debit = 0; //app_account_detail.credit = Convert.ToDecimal(payment_detail.value); //dbContext.db.app_account_detail.Add(app_account_detail); PaymentDB.payments.Add(payment); PaymentDB.MakePayment(payment_schedual, payment, true); imgCancel_MouseDown(null, null); } } else { MessageBox.Show("Please Save and Approve invoice first to Make Payment.", "Cognitivo", MessageBoxButton.OK, MessageBoxImage.Asterisk); } } }
public Payment(Modes App_Mode, List <payment_schedual> _payment_schedualList) { InitializeComponent(); //Setting the Mode for this Window. Result of this variable will determine logic of the certain Behaviours. Mode = App_Mode; paymentViewSource = (CollectionViewSource)this.FindResource("paymentViewSource"); paymentpayment_detailViewSource = (CollectionViewSource)this.FindResource("paymentpayment_detailViewSource"); payment_schedualList = _payment_schedualList; payment payment = new payment(); if (Mode == Modes.Recievable) { payment = PaymentDB.New(true); payment.GrandTotal = payment_schedualList.Sum(x => x.AccountReceivableBalance); } else { payment = PaymentDB.New(false); payment.GrandTotal = payment_schedualList.Sum(x => x.AccountPayableBalance); } PaymentDB.payments.Add(payment); paymentViewSource.Source = PaymentDB.payments.Local; int id_contact = payment_schedualList.FirstOrDefault().id_contact; if (PaymentDB.contacts.Where(x => x.id_contact == id_contact).FirstOrDefault() != null) { payment.id_contact = id_contact; payment.contact = PaymentDB.contacts.Where(x => x.id_contact == id_contact).FirstOrDefault(); } foreach (payment_schedual payment_schedual in payment_schedualList) { if (payment_schedual.payment_detail != null) { payment_detail payment_detail = PaymentDB.payment_detail.Where(x => x.id_payment_detail == payment_schedual.id_payment_detail).FirstOrDefault(); payment_detail.IsSelected = true; payment_detail.id_payment_schedual = payment_schedual.id_payment_schedual; payment.payment_detail.Add(payment_detail); } else { payment_detail payment_detail = new payment_detail(); payment_detail.IsSelected = true; payment_detail.payment = payment; int id_currencyfx = payment_schedual.id_currencyfx; if (PaymentDB.app_currencyfx.Where(x => x.id_currencyfx == id_currencyfx).FirstOrDefault() != null) { payment_detail.id_currencyfx = id_currencyfx; payment_detail.payment.id_currencyfx = id_currencyfx; payment_detail.app_currencyfx = PaymentDB.app_currencyfx.Where(x => x.id_currencyfx == id_currencyfx).FirstOrDefault(); } if (Mode == Modes.Recievable) { payment_detail.value = payment_schedual.AccountReceivableBalance; } else { payment_detail.value = payment_schedual.AccountPayableBalance; } payment_detail.id_payment_schedual = payment_schedual.id_payment_schedual; payment.payment_detail.Add(payment_detail); } } paymentViewSource.View.MoveCurrentTo(payment); paymentpayment_detailViewSource.View.MoveCurrentToFirst(); }
public void add_paymnet_detail(db db, sales_invoice sales_invoice, object SALDOCUOTA, object IMPORTE) { if (!(SALDOCUOTA is DBNull)) { decimal SALDOCUOTAValue = Convert.ToDecimal(SALDOCUOTA); payment_type payment_type; if (SALDOCUOTAValue < sales_invoice.GrandTotal) { if (db.payment_type.Where(x => x.is_default).FirstOrDefault() == null) { payment_type = GenerateDefaultPaymentType(); db.payment_type.Add(payment_type); db.SaveChanges(); } else { payment_type = db.payment_type.Where(x => x.is_default).FirstOrDefault(); } if (IMPORTE is DBNull) { if (sales_invoice.payment_schedual.FirstOrDefault() != null) { payment_schedual payment_schedual = sales_invoice.payment_schedual.FirstOrDefault(); decimal invoice_total = sales_invoice.GrandTotal; if (invoice_total > 0) { payment_detail payment_detail = new payment_detail(); payment_detail.value = invoice_total; if (db.app_account.Where(x => x.id_account_type == app_account.app_account_type.Terminal).FirstOrDefault() != null) { app_account app_account = db.app_account.Where(x => x.id_account_type == app_account.app_account_type.Terminal).FirstOrDefault(); payment_detail.id_account = app_account.id_account; } else { app_account app_account = GenerateDefaultApp_Account(); db.app_account.Add(app_account); payment_detail.app_account = app_account; payment_detail.id_account = app_account.id_account; } payment payment = new payment(); if (payment_schedual != null) { payment.id_contact = payment_schedual.id_contact; payment.contact = payment_schedual.contact; payment_detail.id_currencyfx = payment_schedual.id_currencyfx; payment_detail.id_payment_type = payment_type.id_payment_type; payment_detail.payment_type = payment_type; } payment_detail.App_Name = global::entity.App.Names.SalesInvoice; payment_schedual _payment_schedual = new payment_schedual(); _payment_schedual.credit = invoice_total; _payment_schedual.parent = payment_schedual; _payment_schedual.expire_date = payment_schedual.expire_date; _payment_schedual.status = payment_schedual.status; _payment_schedual.id_contact = payment_schedual.id_contact; _payment_schedual.id_currencyfx = payment_schedual.id_currencyfx; _payment_schedual.id_sales_invoice = payment_schedual.id_sales_invoice; _payment_schedual.trans_date = payment_schedual.trans_date; _payment_schedual.AccountReceivableBalance = invoice_total; payment_detail.payment_schedual.Add(_payment_schedual); payment.payment_detail.Add(payment_detail); //Add Account Logic. With IF FUnction if payment type is Basic Behaviour. If not ignore. app_account_detail app_account_detail = new app_account_detail(); if (db.app_account_session.Where(x => x.id_account == payment_detail.id_account && x.is_active).FirstOrDefault() != null) { app_account_detail.id_session = db.app_account_session.Where(x => x.id_account == payment_detail.id_account && x.is_active).FirstOrDefault().id_session; } app_account_detail.id_account = (int)payment_detail.id_account; app_account_detail.id_currencyfx = payment_schedual.id_currencyfx; app_account_detail.id_payment_type = payment_detail.id_payment_type; app_account_detail.payment_type = payment_type; app_account_detail.debit = 0; app_account_detail.credit = Convert.ToDecimal(payment_detail.value); db.app_account_detail.Add(app_account_detail); try { db.payments.Add(payment); } catch (Exception ex) { throw ex; } } } } } } }
public void ZReport(app_account_session app_account_session) { string Header = string.Empty; string Detail = string.Empty; string Footer = string.Empty; string CompanyName = string.Empty; string BranchName = string.Empty; app_company app_company = null; if (app_account_session.app_company != null) { CompanyName = app_account_session.app_company.name; app_company = app_account_session.app_company; } else { using (db db = new db()) { if (db.app_company.Where(x => x.id_company == app_account_session.id_company).FirstOrDefault() != null) { app_company = db.app_company.Where(x => x.id_company == app_account_session.id_company).FirstOrDefault(); CompanyName = app_company.name; } } } string UserName = ""; if (app_account_session.security_user != null) { UserName = app_account_session.security_user.name; } else { using (db db = new db()) { if (db.security_user.Where(x => x.id_user == app_account_session.id_user).FirstOrDefault() != null) { security_user security_user = db.security_user.Where(x => x.id_user == app_account_session.id_user).FirstOrDefault(); UserName = security_user.name; } } } using (db db = new db()) { if (db.app_branch.Where(x => x.id_branch == CurrentSession.Id_Branch).FirstOrDefault() != null) { app_branch app_branch = db.app_branch.Where(x => x.id_branch == CurrentSession.Id_Branch).FirstOrDefault(); BranchName = app_branch.name; } } string SessionID = app_account_session.id_session.ToString(); DateTime OpenDate = app_account_session.op_date; DateTime CloseDate = DateTime.Now; if (app_account_session.cl_date != null) { CloseDate = (DateTime)app_account_session.cl_date; } Header = "***Z Report***" + "\n" + CompanyName + "\t" + BranchName + "\n" + "R.U.C. :" + app_company.gov_code + "\n" + app_company.address + "\n" + "***" + app_company.alias + "***" + "\n" + "Apertura : " + OpenDate + "\n" + "Cierre : " + CloseDate + "\n" + "--------------------------------" + "\n" + "Hora Factura / Valor Moneda" + "\n" + "--------------------------------" + "\n"; string CustomerName = string.Empty; foreach (app_account_detail detail in app_account_session.app_account_detail.GroupBy(x => x.id_currencyfx).Select(x => x.FirstOrDefault()).ToList()) { Detail += "Moneda : " + detail.app_currencyfx.app_currency.name + "\n"; if (detail.tran_type == app_account_detail.tran_types.Open) { Detail += "Balance de Apertura : " + Math.Round(detail.credit, 2) + "\n"; } foreach (app_account_detail d in app_account_session.app_account_detail.Where(x => x.tran_type == app_account_detail.tran_types.Transaction && x.id_currencyfx == detail.id_currencyfx).ToList()) { string AccountName = string.Empty; if (d.app_account == null) { using (db db = new db()) { app_account app_account = db.app_account.Where(x => x.id_account == d.id_account).FirstOrDefault(); AccountName = app_account.name; } } string currency = string.Empty; if (d.app_currencyfx == null) { using (db db = new db()) { currency = db.app_currencyfx.Where(x => x.id_currencyfx == d.id_currencyfx).FirstOrDefault().app_currency.name; } } string InvoiceNumber = string.Empty; string InvoiceTime = string.Empty; payment_detail payment_detail = d.payment_detail as payment_detail; foreach (payment_schedual payment_schedual in payment_detail.payment_schedual) { if (payment_schedual.sales_invoice.number != null) { if (!(InvoiceNumber.Contains(payment_schedual.sales_invoice.number))) { InvoiceNumber += payment_schedual.sales_invoice.number; InvoiceTime = payment_schedual.sales_invoice.trans_date.ToShortTimeString(); } } } decimal?value = d.credit - d.debit; } var listvat = app_account_session.app_account_detail.Where(x => x.tran_type == app_account_detail.tran_types.Transaction && x.id_currencyfx == detail.id_currencyfx) .GroupBy(a => new { a.id_payment_type, a.id_currencyfx }) .Select(g => new { Currencyname = g.Max(x => x.app_currencyfx).app_currency.name, paymentname = g.Max(x => x.payment_type).name, id_currencyfx = g.Key.id_currencyfx, id_payment_type = g.Key.id_payment_type, value = g.Sum(a => a.credit) }).ToList().OrderBy(x => x.id_currencyfx); Detail += "Total de Ventas Neto :" + Math.Round(listvat.Sum(x => x.value), 2) + "\n"; foreach (dynamic item in listvat) { Detail += item.paymentname + "\t" + Math.Round(item.value, 2) + "\n"; } foreach (app_account_detail account_detail in app_account_session.app_account_detail.Where(x => x.tran_type == app_account_detail.tran_types.Close && x.id_currencyfx == detail.id_currencyfx).GroupBy(x => x.id_currencyfx).Select(x => x.FirstOrDefault()).ToList()) { Detail += "Balance de Cierre : " + Math.Round(account_detail.debit, 2); Detail += "\n--------------------------------" + "\n"; } Detail += "\n--------------------------------" + "\n"; } using (db db = new db()) { decimal amount = 0M; int[] id_schedual = new int[10]; int index = 0; foreach (app_account_detail account_detail in db.app_account_detail.Where(x => x.id_session == app_account_session.id_session && x.tran_type == app_account_detail.tran_types.Transaction).ToList()) { foreach (payment_schedual payment_schedual in account_detail.payment_detail.payment_schedual.ToList()) { if (!id_schedual.Contains(payment_schedual.parent.id_payment_schedual)) { if (payment_schedual.parent != null) { id_schedual[index] = payment_schedual.parent.id_payment_schedual; amount += payment_schedual.parent.debit; } else { amount += payment_schedual.credit; } } } } Detail += "Total de Ventas Neto : " + Math.Round(amount, 2) + " \n"; } Footer += "Cajero/a : " + UserName + " /n"; Footer += "--------------------------------" + " \n"; string Text = Header + Detail + Footer; Reciept Reciept = new Reciept(); PrintDialog pd = new PrintDialog(); FlowDocument document = new FlowDocument(new Paragraph(new Run(Text))); document.Name = "ItemMovement"; document.FontFamily = new FontFamily("Courier New"); document.FontSize = 11.0; document.FontStretch = FontStretches.Normal; document.FontWeight = FontWeights.Normal; document.PagePadding = new Thickness(20); document.PageHeight = double.NaN; document.PageWidth = double.NaN; //document. //Specify minimum page sizes. Origintally 283, but was too small. document.MinPageWidth = 283; //Specify maximum page sizes. document.MaxPageWidth = 300; IDocumentPaginatorSource idpSource = document; try { Nullable <bool> print = pd.ShowDialog(); if (print == true) { pd.PrintDocument(idpSource.DocumentPaginator, Text); } } catch { MessageBox.Show("Output (Reciept Printer) not Found Error", "Error 101"); } }