Beispiel #1
0
        public async void PurchaseInvoice_Click(object sender)
        {
            purchase_return _purchase_return = (purchase_return)purchaseReturnViewSource.View.CurrentItem;

            sbxContact.Text = pnlPurchaseInvoice.selected_purchase_invoice.FirstOrDefault().contact.name;
            foreach (purchase_invoice item in pnlPurchaseInvoice.selected_purchase_invoice)
            {
                _purchase_return.State               = EntityState.Modified;
                _purchase_return.id_condition        = item.id_condition;
                _purchase_return.id_contract         = item.id_contract;
                _purchase_return.id_currencyfx       = item.id_currencyfx;
                _purchase_return.id_purchase_invoice = item.id_purchase_invoice;

                foreach (purchase_invoice_detail _purchase_invoice_detail in item.purchase_invoice_detail)
                {
                    if (_purchase_return.purchase_return_detail.Where(x => x.id_item == _purchase_invoice_detail.id_item).Count() == 0)
                    {
                        purchase_return_detail purchase_return_detail = new purchase_return_detail();
                        purchase_return_detail.id_purchase_invoice_detail = _purchase_invoice_detail.id_purchase_invoice_detail;
                        purchase_return_detail.id_cost_center             = _purchase_invoice_detail.id_cost_center;
                        purchase_return_detail.id_location = _purchase_invoice_detail.id_location;

                        if (dbContext.app_location.Where(x => x.id_location == _purchase_invoice_detail.id_location).FirstOrDefault() != null)
                        {
                            purchase_return_detail.app_location = dbContext.app_location.Where(x => x.id_location == _purchase_invoice_detail.id_location).FirstOrDefault();
                        }

                        purchase_return_detail.purchase_return = _purchase_return;

                        if (dbContext.items.Where(x => x.id_item == _purchase_invoice_detail.id_item).FirstOrDefault() != null)
                        {
                            purchase_return_detail.id_item = _purchase_invoice_detail.id_item;
                            purchase_return_detail.item    = dbContext.items.Where(x => x.id_item == _purchase_invoice_detail.id_item).FirstOrDefault();
                        }

                        purchase_return_detail.item_description = _purchase_invoice_detail.item_description;

                        purchase_return_detail.quantity = _purchase_invoice_detail.quantity - dbContext.purchase_return_detail
                                                          .Where(x => x.id_purchase_invoice_detail == _purchase_invoice_detail.id_purchase_invoice_detail)
                                                          .GroupBy(x => x.id_purchase_invoice_detail).Select(x => x.Sum(y => y.quantity)).FirstOrDefault();

                        purchase_return_detail.id_vat_group  = _purchase_invoice_detail.id_vat_group;
                        purchase_return_detail.unit_cost     = _purchase_invoice_detail.unit_cost;
                        purchase_return_detail.CurrencyFX_ID = _purchase_return.id_currencyfx;
                        _purchase_return.purchase_return_detail.Add(purchase_return_detail);
                    }
                    dbContext.Entry(_purchase_return).Entity.State = EntityState.Added;
                    crud_modal.Children.Clear();
                    crud_modal.Visibility = Visibility.Collapsed;
                    purchaseReturnViewSource.View.Refresh();

                    purchase_returnpurchase_return_detailViewSource.View.Refresh();
                }
            }
        }
Beispiel #2
0
        public void Fill_ByPurchaseReturn(purchase_return_detail Detail, db db)
        {
            this.VAT_Coeficient    = Detail.app_vat_group.app_vat_group_details.Sum(x => x.app_vat.coefficient);
            this.UnitValue_WithVAT = Detail.SubTotal_Vat;
            this.Comment           = Detail.item_description;

            entity.DebeHaber.CostCenter CostCenter = new entity.DebeHaber.CostCenter();

            //Check if Purchase has Item. If not its an expense.
            if (Detail.item != null)
            {
                // If Item being sold is FixedAsset, get Cost Center will be the GroupName.
                if (Detail.item.id_item_type == entity.item.item_type.FixedAssets)
                {
                    CostCenter.Name = db.item_asset.Where(x => x.id_item == Detail.id_item).FirstOrDefault().item_asset_group != null?db.item_asset.Where(x => x.id_item == Detail.id_item).FirstOrDefault().item_asset_group.name : "";

                    CostCenter.Type = entity.DebeHaber.CostCenterTypes.FixedAsset;

                    //Add CostCenter into Detail.
                    this.CostCenter.Add(CostCenter);
                }
                // If Item being sold is a Service, Contract, or Task. Take it as Direct Revenue.
                else if (Detail.item.id_item_type == entity.item.item_type.Service || Detail.item.id_item_type == entity.item.item_type.Task || Detail.item.id_item_type == entity.item.item_type.ServiceContract)
                {
                    if (db.items.Where(x => x.id_item == Detail.id_item).FirstOrDefault().item_tag_detail.FirstOrDefault() != null)
                    {
                        CostCenter.Name = db.items.Where(x => x.id_item == Detail.id_item).FirstOrDefault().item_tag_detail.FirstOrDefault().item_tag.name;
                    }
                    else
                    {
                        CostCenter.Name = Detail.item_description;
                    }

                    CostCenter.Type = entity.DebeHaber.CostCenterTypes.Income;

                    //Add CostCenter into Detail.
                    this.CostCenter.Add(CostCenter);
                }
                // Finally if all else fails, assume Item being sold is Merchendice.
                else
                {
                    if (db.app_cost_center.Where(x => x.is_product).FirstOrDefault() != null)
                    {
                        CostCenter.Name = db.app_cost_center.Where(x => x.is_product).FirstOrDefault().name;
                        CostCenter.Type = entity.DebeHaber.CostCenterTypes.Merchendice;
                    }
                    else
                    {
                        CostCenter.Name = "Mercaderia";
                        CostCenter.Type = entity.DebeHaber.CostCenterTypes.Merchendice;
                    }

                    //Add CostCenter into Detail.
                    this.CostCenter.Add(CostCenter);
                }
            }
            else
            {
                CostCenter.Name = db.app_cost_center.Where(x => x.is_administrative).FirstOrDefault().name;
                CostCenter.Type = entity.DebeHaber.CostCenterTypes.Expense;

                //Add CostCenter into Detail.
                this.CostCenter.Add(CostCenter);
            }
        }
Beispiel #3
0
 private void item_Select(object sender, EventArgs e)
 {
     try
     {
         if (sbxItem.ItemID > 0)
         {
             item                   item                   = dbContext.items.Where(x => x.id_item == sbxItem.ItemID).FirstOrDefault();
             purchase_return        purchase_return        = purchase_returnDataGrid.SelectedItem as purchase_return;
             purchase_return_detail purchase_return_detail = purchase_return.purchase_return_detail.Where(a => a.id_item == sbxItem.ItemID).FirstOrDefault();
             int id_cost_center = 0;
             if (purchase_return_detail == null)
             {
                 purchase_return_detail _purchase_return_detail = new entity.purchase_return_detail();
                 //Check for contact
                 if (sbxContact.ContactID > 0)
                 {
                     contact contact = dbContext.contacts.Where(x => x.id_contact == sbxContact.ContactID).FirstOrDefault();
                     if (contact.app_cost_center != null)
                     {
                         app_cost_center app_cost_center = contact.app_cost_center as app_cost_center;
                         if (app_cost_center.is_product == true)
                         {
                             id_cost_center = app_cost_center.id_cost_center;
                             if (id_cost_center > 0)
                             {
                                 _purchase_return_detail.id_cost_center = id_cost_center;
                             }
                         }
                         else
                         {
                             if (dbContext.app_cost_center.Where(a => a.is_product == true && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault() != null)
                             {
                                 id_cost_center = Convert.ToInt32(dbContext.app_cost_center.Where(a => a.is_product == true && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault().id_cost_center);
                             }
                             if (id_cost_center > 0)
                             {
                                 _purchase_return_detail.id_cost_center = id_cost_center;
                             }
                         }
                     }
                     else
                     {
                         if (dbContext.app_cost_center.Where(a => a.is_product == true && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault() != null)
                         {
                             id_cost_center = Convert.ToInt32(dbContext.app_cost_center.Where(a => a.is_product == true && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault().id_cost_center);
                         }
                         if (id_cost_center > 0)
                         {
                             _purchase_return_detail.id_cost_center = id_cost_center;
                         }
                     }
                 }
                 else
                 {
                     if (dbContext.app_cost_center.Where(a => a.is_product == true && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault() != null)
                     {
                         id_cost_center = Convert.ToInt32(dbContext.app_cost_center.Where(a => a.is_product == true && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault().id_cost_center);
                     }
                     if (id_cost_center > 0)
                     {
                         _purchase_return_detail.id_cost_center = id_cost_center;
                     }
                 }
                 if (dbContext.app_vat_group.Where(x => x.is_active == true && x.is_default == true && x.id_company == _entity.company_ID).FirstOrDefault() != null)
                 {
                     _purchase_return_detail.id_vat_group = dbContext.app_vat_group.Where(x => x.is_active == true && x.is_default == true && x.id_company == _entity.company_ID).FirstOrDefault().id_vat_group;
                 }
                 _purchase_return_detail.purchase_return = purchase_return;
                 _purchase_return_detail.item            = item;
                 _purchase_return_detail.id_item         = sbxItem.ItemID;
                 purchase_return.purchase_return_detail.Add(_purchase_return_detail);
             }
             else
             {
                 purchase_return_detail.quantity += 1;
             }
             purchase_returnpurchase_return_detailViewSource.View.Refresh();
             //calculate_total(sender, e);
             calculate_vat(sender, e);
         }
         else
         {
             //Other
             purchase_return        purchase_return        = purchase_returnDataGrid.SelectedItem as purchase_return;
             purchase_return_detail purchase_return_detail = purchase_return.purchase_return_detail.Where(a => a.item_description == sbxItem.Text).FirstOrDefault();
             if (purchase_return_detail == null)
             {
                 purchase_return_detail _purchase_return_detail = new entity.purchase_return_detail();
                 int id_cost_center = 0;
                 //Check for contact
                 if (sbxContact.ContactID > 0)
                 {
                     contact contact = dbContext.contacts.Where(x => x.id_contact == sbxContact.ContactID).FirstOrDefault();
                     if (contact.app_cost_center != null)
                     {
                         app_cost_center app_cost_center = contact.app_cost_center as app_cost_center;
                         if (app_cost_center.is_product == false)
                         {
                             id_cost_center = app_cost_center.id_cost_center;
                             if (id_cost_center > 0)
                             {
                                 _purchase_return_detail.id_cost_center = id_cost_center;
                             }
                         }
                         else
                         {
                             if (dbContext.app_cost_center.Where(a => a.is_product == false && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault() != null)
                             {
                                 id_cost_center = Convert.ToInt32(dbContext.app_cost_center.Where(a => a.is_product == false && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault().id_cost_center);
                             }
                             if (id_cost_center > 0)
                             {
                                 _purchase_return_detail.id_cost_center = id_cost_center;
                             }
                         }
                     }
                     else
                     {
                         if (dbContext.app_cost_center.Where(a => a.is_product == false && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault() != null)
                         {
                             id_cost_center = Convert.ToInt32(dbContext.app_cost_center.Where(a => a.is_product == false && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault().id_cost_center);
                         }
                         if (id_cost_center > 0)
                         {
                             _purchase_return_detail.id_cost_center = id_cost_center;
                         }
                     }
                 }
                 else
                 {
                     if (dbContext.app_cost_center.Where(a => a.is_product == false && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault() != null)
                     {
                         id_cost_center = Convert.ToInt32(dbContext.app_cost_center.Where(a => a.is_product == false && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault().id_cost_center);
                     }
                     if (id_cost_center > 0)
                     {
                         _purchase_return_detail.id_cost_center = id_cost_center;
                     }
                 }
                 if (dbContext.app_vat_group.Where(x => x.is_active == true && x.is_default == true && x.id_company == _entity.company_ID).FirstOrDefault() != null)
                 {
                     _purchase_return_detail.id_vat_group = dbContext.app_vat_group.Where(x => x.is_active == true && x.is_default == true && x.id_company == _entity.company_ID).FirstOrDefault().id_vat_group;
                 }
                 _purchase_return_detail.purchase_return  = purchase_return;
                 _purchase_return_detail.item_description = sbxItem.Text;
                 _purchase_return_detail.id_item          = 0;
                 purchase_return.purchase_return_detail.Add(_purchase_return_detail);
             }
             else
             {
                 purchase_return_detail.quantity += 1;
             }
             purchase_returnpurchase_return_detailViewSource.View.Refresh();
             calculate_vat(sender, e);
         }
     }
     catch (Exception)
     {
         //throw ex;
     }
 }
Beispiel #4
0
 private void purchase_return_detailDataGrid_InitializingNewItem(object sender, InitializingNewItemEventArgs e)
 {
     purchase_return_detail purchase_return_detail = (purchase_return_detail)e.NewItem;
     purchase_return        purchase_return        = (purchase_return)purchase_returnDataGrid.SelectedItem;
 }