Beispiel #1
0
 private sales_invoice_detail select_Item(ref sales_invoice sales_invoice, item item, bool AllowDuplicateItem)
 {
     if (sales_invoice.sales_invoice_detail.Where(a => a.id_item == item.id_item && a.IsPromo == false).FirstOrDefault() == null || AllowDuplicateItem)
     {
         return(AddDetail(ref sales_invoice, item));
     }
     else
     {
         sales_invoice_detail sales_invoice_detail = sales_invoice.sales_invoice_detail.Where(a => a.id_item == item.id_item).FirstOrDefault();
         sales_invoice_detail.quantity += 1;
         return(sales_invoice_detail);
     }
 }
Beispiel #2
0
        public sales_invoice_detail AddDetail(ref sales_invoice sales_invoice, item item)
        {
            sales_invoice_detail _sales_invoice_detail = new sales_invoice_detail();

            _sales_invoice_detail.State         = EntityState.Added;
            _sales_invoice_detail.sales_invoice = sales_invoice;

            _sales_invoice_detail.CurrencyFX_ID    = sales_invoice.app_currencyfx.id_currencyfx;
            _sales_invoice_detail.Contact          = sales_invoice.contact;
            _sales_invoice_detail.item_description = item.name;
            _sales_invoice_detail.item             = item;
            _sales_invoice_detail.id_item          = item.id_item;

            _sales_invoice_detail.quantity     += 1;
            _sales_invoice_detail.app_vat_group = base.app_vat_group.Where(x => x.id_vat_group == _sales_invoice_detail.id_vat_group).FirstOrDefault();
            sales_invoice.sales_invoice_detail.Add(_sales_invoice_detail);
            return(_sales_invoice_detail);
        }
Beispiel #3
0
        private void add_CRM(sales_return sales_return)
        {
            sales_invoice_detail sales_invoice_detail = sales_return.sales_return_detail.FirstOrDefault().sales_invoice_detail;

            if (sales_invoice_detail == null)
            {
                crm_opportunity crm_opportunity = new crm_opportunity();
                crm_opportunity.id_contact  = sales_return.id_contact;
                crm_opportunity.id_currency = sales_return.id_currencyfx;
                crm_opportunity.value       = sales_return.GrandTotal;

                crm_opportunity.sales_return.Add(sales_return);
                base.crm_opportunity.Add(crm_opportunity);
            }
            else
            {
                crm_opportunity crm_opportunity = sales_invoice.Where(x => x.id_sales_invoice == sales_invoice_detail.id_sales_invoice).FirstOrDefault().crm_opportunity;
                crm_opportunity.sales_return.Add(sales_return);
                base.crm_opportunity.Attach(crm_opportunity);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Split Invoice from the particular invoice
        /// </summary>
        /// <param name="invoice">object for the sales invoice</param>
        public void SpiltInvoice(sales_invoice invoice)
        {
            if ((invoice.number == null || invoice.number == string.Empty) && invoice.app_document_range != null)
            {
                int document_line_limit = 0;

                if (invoice.app_document_range.app_document.line_limit != null)
                {
                    document_line_limit = (int)invoice.app_document_range.app_document.line_limit;
                }

                if (document_line_limit > 0 && invoice.sales_invoice_detail.Count > document_line_limit)
                {
                    int NoOfInvoice = (int)Math.Ceiling(invoice.sales_invoice_detail.Count / (decimal)document_line_limit);

                    //Counter Variable for not loosing place in Detail
                    int position = 0;

                    for (int i = 1; i <= NoOfInvoice; i++)
                    {
                        sales_invoice _invoice = new sales_invoice();
                        _invoice.code    = invoice.code;
                        _invoice.comment = invoice.comment;
                        // _invoice.CreditLimit = invoice.CreditLimit;
                        _invoice.id_branch          = invoice.id_branch;
                        _invoice.id_company         = invoice.id_company;
                        _invoice.id_condition       = invoice.id_condition;
                        _invoice.id_contact         = invoice.id_contact;
                        _invoice.id_contract        = invoice.id_contract;
                        _invoice.id_currencyfx      = invoice.id_currencyfx;
                        _invoice.id_opportunity     = invoice.id_opportunity;
                        _invoice.id_project         = invoice.id_project;
                        _invoice.id_range           = invoice.id_range;
                        _invoice.id_sales_order     = invoice.id_sales_order;
                        _invoice.id_sales_rep       = invoice.id_sales_rep;
                        _invoice.id_terminal        = invoice.id_terminal;
                        _invoice.id_user            = invoice.id_user;
                        _invoice.id_weather         = invoice.id_weather;
                        _invoice.number             = invoice.number;
                        _invoice.GrandTotal         = invoice.GrandTotal;
                        _invoice.accounting_journal = invoice.accounting_journal;
                        _invoice.is_head            = invoice.is_head;
                        _invoice.is_issued          = invoice.is_issued;
                        _invoice.IsSelected         = invoice.IsSelected;
                        _invoice.State  = EntityState.Added;
                        _invoice.status = Status.Documents_General.Pending;


                        foreach (sales_invoice_detail detail in invoice.sales_invoice_detail.Skip(position).Take(document_line_limit))
                        {
                            sales_invoice_detail sales_invoice_detail = new sales_invoice_detail();
                            sales_invoice_detail.item_description      = detail.item_description;
                            sales_invoice_detail.discount              = detail.discount;
                            sales_invoice_detail.id_company            = detail.id_company;
                            sales_invoice_detail.id_item               = detail.id_item;
                            sales_invoice_detail.id_location           = detail.id_location;
                            sales_invoice_detail.id_project_task       = detail.id_project_task;
                            sales_invoice_detail.id_sales_order_detail = detail.id_sales_order_detail;
                            sales_invoice_detail.id_vat_group          = detail.id_vat_group;
                            sales_invoice_detail.is_head               = detail.is_head;
                            sales_invoice_detail.IsSelected            = detail.IsSelected;
                            sales_invoice_detail.quantity              = detail.quantity;
                            sales_invoice_detail.State         = EntityState.Added;
                            sales_invoice_detail.SubTotal      = detail.SubTotal;
                            sales_invoice_detail.SubTotal_Vat  = detail.SubTotal_Vat;
                            sales_invoice_detail.unit_cost     = detail.unit_cost;
                            sales_invoice_detail.unit_price    = detail.unit_price;
                            sales_invoice_detail.UnitPrice_Vat = detail.UnitPrice_Vat;
                            _invoice.sales_invoice_detail.Add(sales_invoice_detail);
                            position += 1;
                        }
                        sales_invoice.Add(_invoice);
                    }

                    invoice.is_head = false;
                    invoice.status  = Status.Documents_General.Approved;

                    SaveChanges();
                }
            }
        }