Ejemplo n.º 1
0
        public async Task <HttpResponseMessage> loadInvoiceData([FromBody] int id)
        {
            try
            {
            }
            catch (Exception ex)
            {
                throw;
            }
            var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId);

            var resualt = new InvoiceData();

            List <ContactVM> contacts    = new List <ContactVM>();
            ContactRule      contactRule = new ContactRule();

            var contactsSource = await contactRule.GetAllByOrganIdAsync(Convert.ToInt32(organId));

            contactsSource = contactsSource.ToList();

            contacts = TranslateHelper.TranslateEntityToEntityVMListContact(contactsSource);

            foreach (var contact in contacts)
            {
                contact.DetailAccount = new DetailAccount()
                {
                    Code = contact.Code,
                    Id   = (int)contact.ID,
                    Node = new Node()
                    {
                        FamilyTree = "اشخاص",
                        Id         = (int)contact.ID,
                        Name       = "اشخاص"
                    }
                };

                //var account1104 = await CalcAccountByCodeTafziliAsync(organId, "1104" + contact.Code);
                //var account1105 = await CalcAccountByCodeTafziliAsync(organId, "1105" + contact.Code);
                //var account2101 = await CalcAccountByCodeTafziliAsync(organId, "2101" + contact.Code);

                //contact.Balance = account1104.sumTotal + account1105.sumTotal + account2101.sumTotal;
                //contact.Credits = account1104.sumCredit + account1105.sumCredit + account2101.sumCredit;
                //contact.Liability = account1104.sumDebit + account1105.sumDebit + account2101.sumDebit;
            }



            resualt.contacts        = contacts;
            resualt.invoiceSettings = new InvoiceSettings()
            {
                allowApproveWithoutStock = false,
                autoAddTax            = true,
                bottomMargin          = "20",
                businessLogo          = "",
                font                  = "Iransans",
                fontSize              = "Medium",
                footerNote            = "",
                footerNoteDraft       = "",
                hideZeroItems         = false,
                onlineInvoiceEnabled  = false,
                pageSize              = "A4portrait",
                payReceiptTitle       = "رسید پرداخت وجه / چک",
                purchaseInvoiceTitle  = "فاکتور خرید",
                receiveReceiptTitle   = "رسید دریافت وجه / چک",
                rowPerPage            = "18",
                saleDraftInvoiceTitle = "پیش فاکتور",
                saleInvoiceTitle      = "صورتحساب فروش کالا و خدمات",
                showAmountInWords     = false,
                showCustomerBalance   = false,
                showItemUnit          = false,
                showSignaturePlace    = true,
                showTransactions      = true,
                showVendorInfo        = true,
                topMargin             = "10",
                updateBuyPrice        = false,
                updateSellPrice       = false
            };

            ItemGroupRule itemGroupRule = new ItemGroupRule();
            var           itemGroups    = await itemGroupRule.GetAllByOrganIdAsync(Convert.ToInt32(organId));

            var items = new List <ItemVM>();
            var item  = new ItemVM();

            foreach (var itemGroup in itemGroups)
            {
                foreach (var KalaKhadmat in itemGroup.Items)
                {
                    item = new ItemVM()
                    {
                        Barcode       = "",
                        BuyPrice      = KalaKhadmat.BuyPrice,
                        DetailAccount = new DetailAccount()
                        {
                            Code = KalaKhadmat.Code,
                            Id   = KalaKhadmat.ID,
                            Node = new Node()
                            {
                                FamilyTree = itemGroup.Name,
                                Name       = itemGroup.Name,
                                Id         = itemGroup.ID
                            }
                        },
                        ID             = KalaKhadmat.ID,
                        Name           = KalaKhadmat.Name,
                        UnitID         = KalaKhadmat.UnitID,
                        SalesTitle     = KalaKhadmat.SalesTitle,
                        PurchasesTitle = KalaKhadmat.PurchasesTitle,
                        SellPrice      = KalaKhadmat.SellPrice,
                        ItemType       = KalaKhadmat.ItemType,
                        Stock          = KalaKhadmat.Stock,
                        Code           = KalaKhadmat.Code,
                        IsGoods        = KalaKhadmat.IsGoods,
                        IsService      = KalaKhadmat.IsService,
                        MoneyStock     = KalaKhadmat.MoneyStock,
                        OrganId        = KalaKhadmat.OrganId,
                        ItemGroupId    = KalaKhadmat.ItemGroupId
                    };

                    items.Add(item);
                }
            }

            resualt.items = items;

            var InvoiceItems = new List <InvoiceItemVM>();


            if (id == 0)
            {
                InvoiceItems.Add(new InvoiceItemVM()
                {
                    Description = "",
                    Discount    = 0,
                    ID          = 0,
                    Inv         = null,
                    Item        = null,
                    ItemInput   = "",
                    Quantity    = 0,
                    RowNumber   = 0,
                    Sum         = 0,
                    Tax         = 0,
                    TotalAmount = 0,
                    Unit        = 0,
                    UnitPrice   = 0
                });

                InvoiceItems.Add(new InvoiceItemVM()
                {
                    Description = "",
                    Discount    = 0,
                    ID          = 0,
                    Inv         = null,
                    Item        = null,
                    ItemInput   = "",
                    Quantity    = 0,
                    RowNumber   = 1,
                    Sum         = 0,
                    Tax         = 0,
                    TotalAmount = 0,
                    Unit        = 0,
                    UnitPrice   = 0
                });

                InvoiceItems.Add(new InvoiceItemVM()
                {
                    Description = "",
                    Discount    = 0,
                    ID          = 0,
                    Inv         = null,
                    Item        = null,
                    ItemInput   = "",
                    Quantity    = 0,
                    RowNumber   = 2,
                    Sum         = 0,
                    Tax         = 0,
                    TotalAmount = 0,
                    Unit        = 0,
                    UnitPrice   = 0
                });

                InvoiceItems.Add(new InvoiceItemVM()
                {
                    Description = "",
                    Discount    = 0,
                    ID          = 0,
                    Inv         = null,
                    Item        = null,
                    ItemInput   = "",
                    Quantity    = 0,
                    RowNumber   = 3,
                    Sum         = 0,
                    Tax         = 0,
                    TotalAmount = 0,
                    Unit        = 0,
                    UnitPrice   = 0
                });

                resualt.invoice = new InvoiceVM()
                {
                    Contact        = null,
                    ContactTitle   = "",
                    DateTime       = DateTime.Now,
                    DisplayDate    = PersianDateUtils.ToPersianDate(DateTime.Now),
                    DisplayDueDate = PersianDateUtils.ToPersianDate(DateTime.Now),
                    invoiceDueDate = PersianDateUtils.ToPersianDate(DateTime.Now),

                    DueDate             = DateTime.Now,
                    ID                  = 0,
                    InvoiceItems        = InvoiceItems,
                    InvoiceStatusString = "موقت",
                    InvoiceType         = 0,
                    InvoiceTypeString   = "فروش",
                    IsDraft             = true,
                    IsPurchase          = false,
                    IsPurchaseReturn    = false,
                    IsSale              = true,
                    IsSaleReturn        = false,
                    IsWaste             = false,
                    Note                = "",
                    Number              = await createNumberInvoice(organId),
                    Paid                = 0,
                    Payable             = 0,
                    Profit              = 0,
                    Reference           = "",
                    Rest                = 0,
                    Returned            = false,
                    Sent                = false,
                    Status              = 0,
                    Sum                 = 0,
                    Tag                 = ""
                };
            }
            else
            {
                var invoice = await Rule.FindAsync(id);

                foreach (var invoiceItem in invoice.InvoiceItems ?? new List <InvoiceItem>())
                {
                    InvoiceItems.Add(new InvoiceItemVM()
                    {
                        Description = invoiceItem.Description,
                        Discount    = invoiceItem.Discount,
                        ID          = invoiceItem.ID,
                        Inv         = invoiceItem.Inv,
                        Item        = Mapper.Map <Item, ItemVM>(this.BusinessRule.UnitOfWork.Repository <Item>().Find(invoiceItem.ItemId)),
                        ItemId      = invoiceItem.ItemId,
                        ItemInput   = invoiceItem.ItemInput,
                        Quantity    = invoiceItem.Quantity,
                        RowNumber   = invoiceItem.RowNumber,
                        Sum         = invoiceItem.SumInvoiceItem,
                        Tax         = invoiceItem.Tax,
                        TotalAmount = invoiceItem.TotalAmount,
                        Unit        = invoiceItem.UnitInvoiceItem,
                        UnitPrice   = invoiceItem.UnitPrice
                    });
                }



                resualt.invoice = new InvoiceVM()
                {
                    Contact        = Mapper.Map <Contact, ContactVM>(this.BusinessRule.UnitOfWork.Repository <Contact>().Find(invoice.ContactId)),
                    ContactTitle   = invoice.ContactTitle,
                    DateTime       = invoice.DateTime,
                    DisplayDate    = invoice.DisplayDate,
                    DisplayDueDate = invoice.DisplayDueDate,
                    invoiceDueDate = invoice.DisplayDueDate,

                    DueDate             = invoice.DueDate,
                    ID                  = invoice.ID,
                    InvoiceItems        = InvoiceItems,
                    InvoiceStatusString = invoice.InvoiceStatusString,
                    InvoiceType         = invoice.InvoiceType,
                    InvoiceTypeString   = invoice.InvoiceTypeString,
                    IsDraft             = invoice.IsDraft,
                    IsPurchase          = invoice.IsPurchase,
                    IsPurchaseReturn    = invoice.IsPurchaseReturn,
                    IsSale              = invoice.IsSale,
                    IsSaleReturn        = invoice.IsSaleReturn,
                    IsWaste             = false,
                    Note                = invoice.Note,
                    Number              = invoice.Number,
                    Paid                = invoice.Paid,
                    Payable             = invoice.Payable,
                    Profit              = invoice.Profit,
                    Reference           = invoice.Refrence,
                    Rest                = invoice.Rest,
                    Returned            = invoice.Returned,
                    Sent                = invoice.Sent,
                    Status              = invoice.Status,
                    Sum                 = invoice.Sum,
                    Tag                 = invoice.Tag
                };

                return(Request.CreateResponse(HttpStatusCode.OK, new { resualtCode = (int)ZhivarEnums.ResultCode.Successful, data = resualt }));
            }
            return(Request.CreateResponse(HttpStatusCode.OK, new { resualtCode = (int)ZhivarEnums.ResultCode.Successful, data = resualt }));
        }
Ejemplo n.º 2
0
        public async Task <HttpResponseMessage> loadReservationData([FromBody] loadReservationDataBusi reservationData)
        {
            try
            {
                var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId);

                var resualt = new ReservationData();

                List <ContactVM> contacts    = new List <ContactVM>();
                ContactRule      contactRule = new ContactRule();

                var contactsSource = await contactRule.GetAllByOrganIdAsync(Convert.ToInt32(organId));

                contactsSource = contactsSource.ToList();

                contacts = TranslateHelper.TranslateEntityToEntityVMListContact(contactsSource);

                foreach (var contact in contacts)
                {
                    contact.DetailAccount = new DetailAccount()
                    {
                        Code = contact.Code,
                        Id   = (int)contact.ID,
                        Node = new Node()
                        {
                            FamilyTree = "اشخاص",
                            Id         = (int)contact.ID,
                            Name       = "اشخاص"
                        }
                    };
                }



                resualt.contacts = contacts;



                NoeEjareRule noeEjareRule = new NoeEjareRule();
                var          noeEjares    = await noeEjareRule.GetAllByOrganIdAsync(Convert.ToInt32(organId));

                resualt.noeEjares = noeEjares;

                GoroheSazeRule goroheSazeRule = new GoroheSazeRule();
                var            itemGroups     = await goroheSazeRule.GetAllByOrganIdAsync(Convert.ToInt32(organId));

                var items = new List <SazeVM>();
                var item  = new SazeVM();

                foreach (var itemGroup in itemGroups)
                {
                    foreach (var KalaKhadmat in itemGroup.Items)
                    {
                        item = new SazeVM()
                        {
                            DetailAccount = new DetailAccount()
                            {
                                Code = KalaKhadmat.Code,
                                Id   = KalaKhadmat.ID,
                                Node = new Node()
                                {
                                    FamilyTree = itemGroup.Title,
                                    Name       = itemGroup.Title,
                                    Id         = itemGroup.ID
                                }
                            },
                            Code         = KalaKhadmat.Code,
                            OrganId      = KalaKhadmat.OrganId,
                            Address      = KalaKhadmat.Address,
                            Arz          = KalaKhadmat.Arz,
                            GoroheSazeID = KalaKhadmat.GoroheSazeID,
                            ID           = KalaKhadmat.ID,
                            Title        = KalaKhadmat.Title,
                            Tol          = KalaKhadmat.Tol,
                            NoeSazeId    = KalaKhadmat.NoeSazeId,
                            NoeEjare     = KalaKhadmat.NoeEjare,
                            GoroheName   = KalaKhadmat.GoroheName,
                            NoeEjareName = KalaKhadmat.NoeEjareName,
                            NoeSazeName  = KalaKhadmat.NoeSazeName,
                            Latitude     = KalaKhadmat.Latitude,
                            Longitude    = KalaKhadmat.Longitude,
                            NoorDard     = KalaKhadmat.NoorDard,
                            NoeEjareID   = KalaKhadmat.NoeEjareID,
                        };

                        items.Add(item);
                    }
                }

                resualt.items = items;

                var Reservation_DetailVMs = new List <Reservation_DetailVM>();

                var reservation_DetailVM = new List <Reservation_DetailVM>();

                if (reservationData.id == 0)
                {
                    var countRes = 0;
                    if (reservationData.lstSaze != null && reservationData.lstSaze.Count > 0)
                    {
                        reservationData.lstSaze = reservationData.lstSaze.Where(x => x.sazeID != 0).ToList();

                        foreach (var lstSaze in reservationData.lstSaze)
                        {
                            var saze = Mapper.Map <Saze, SazeVM>(this.BusinessRule.UnitOfWork.Repository <Saze>().Find(lstSaze.sazeID));

                            var startDate        = DateTime.Now;
                            var displayStartDate = PersianDateUtils.ToPersianDateTime(DateTime.Now);

                            bool minValue = false;
                            bool maxValue = false;

                            if (!string.IsNullOrEmpty(lstSaze.minDate) && !string.IsNullOrWhiteSpace(lstSaze.minDate))
                            {
                                startDate        = PersianDateUtils.ToDateTime(lstSaze.minDate);
                                displayStartDate = lstSaze.minDate;
                                minValue         = true;
                            }

                            var endDate        = DateTime.Now;
                            var displayEndDate = PersianDateUtils.ToPersianDateTime(DateTime.Now);

                            if (!string.IsNullOrEmpty(lstSaze.maxDate) && !string.IsNullOrWhiteSpace(lstSaze.maxDate))
                            {
                                endDate          = PersianDateUtils.ToDateTime(lstSaze.maxDate);
                                displayStartDate = lstSaze.maxDate;
                                maxValue         = true;
                            }

                            var quantity = 0;

                            if (minValue && maxValue)
                            {
                                var diff = endDate - startDate;
                                var days = diff.TotalDays;

                                quantity = Convert.ToInt32(days);
                            }


                            Reservation_DetailVMs.Add(new Reservation_DetailVM()
                            {
                                ID               = 0,
                                Quantity         = quantity,
                                Saze             = saze,
                                SazeID           = saze.ID,
                                NoeEjare         = Mapper.Map <NoeEjare, NoeEjareVM>(this.BusinessRule.UnitOfWork.Repository <NoeEjare>().Find(saze.NoeEjareID)),
                                NoeEjareID       = saze.NoeEjareID,
                                RowNumber        = 0,
                                StartDate        = startDate,
                                StartDisplayDate = displayStartDate,
                                //EndDate = endDate,
                                //EndDisplayDate = lstSaze.maxDate,
                            });
                            countRes += 1;
                        }


                        if (countRes < 3)
                        {
                            for (int i = 0; i < 3 - countRes; i++)
                            {
                                Reservation_DetailVMs.Add(new Reservation_DetailVM()
                                {
                                    ID         = 0,
                                    Quantity   = 0,
                                    Saze       = null,
                                    SazeID     = 0,
                                    NoeEjare   = null,
                                    NoeEjareID = 0,
                                    RowNumber  = countRes + i,
                                    //StartDate = startDate,
                                    StartDisplayDate = "",
                                    //EndDate = endDate,
                                    //EndDisplayDate = lstSaze.maxDate,
                                });
                            }
                        }
                    }
                    else
                    {
                        Reservation_DetailVMs.Add(new Reservation_DetailVM()
                        {
                            ID        = 0,
                            Quantity  = 0,
                            RowNumber = 0
                        });

                        Reservation_DetailVMs.Add(new Reservation_DetailVM()
                        {
                            ID        = 0,
                            Quantity  = 0,
                            RowNumber = 1
                        });

                        Reservation_DetailVMs.Add(new Reservation_DetailVM()
                        {
                            ID        = 0,
                            Quantity  = 0,
                            RowNumber = 2
                        });

                        Reservation_DetailVMs.Add(new Reservation_DetailVM()
                        {
                            ID        = 0,
                            Quantity  = 0,
                            RowNumber = 3
                        });
                    }



                    resualt.Reservation = new ReservationVM()
                    {
                        //Contact = Mapper.Map<Contact, ContactVM>(this.BusinessRule.UnitOfWork.Repository<Contact>().Find(reservation.ContactID)),

                        ID = 0,
                        DisplayRegisterDate = Utilities.PersianDateUtils.ToPersianDateTime(DateTime.Now),
                        // ContactID = reservation.ContactID,
                        OrganID      = organId,
                        RegisterDate = DateTime.Now,

                        ReservationDetails = Reservation_DetailVMs
                    };

                    return(Request.CreateResponse(HttpStatusCode.OK, new { resualtCode = (int)ZhivarEnums.ResultCode.Successful, data = resualt }));
                }
                else
                {
                    var reservation = await Rule.FindAsync(reservationData.id);

                    foreach (var reservationDetail in reservation.ReservationDetails ?? new List <Reservation_Detail>())
                    {
                        Reservation_DetailVMs.Add(new Reservation_DetailVM()
                        {
                            ID               = reservationDetail.ID,
                            Saze             = Mapper.Map <Saze, SazeVM>(this.BusinessRule.UnitOfWork.Repository <Saze>().Find(reservationDetail.SazeID)),
                            SazeID           = reservationDetail.SazeID,
                            Quantity         = reservationDetail.Quantity,
                            NoeEjare         = Mapper.Map <NoeEjare, NoeEjareVM>(this.BusinessRule.UnitOfWork.Repository <NoeEjare>().Find(reservationDetail.NoeEjareID)),
                            NoeEjareID       = reservationDetail.NoeEjareID,
                            EndDate          = reservationDetail.EndDate,
                            EndDisplayDate   = reservationDetail.EndDisplayDate,
                            ReservationID    = reservationDetail.ReservationID,
                            StartDate        = reservationDetail.StartDate,
                            StartDisplayDate = reservationDetail.StartDisplayDate,
                            UnitPrice        = reservationDetail.UnitPrice,
                            PriceBazareab    = reservationDetail.PriceBazareab,
                            PriceTarah       = reservationDetail.PriceTarah,
                            PriceChap        = reservationDetail.PriceChap,
                            PriceNasab       = reservationDetail.PriceNasab,
                            RowNumber        = reservationDetail.RowNumber
                        });
                    }


                    resualt.Reservation = new ReservationVM()
                    {
                        Contact = Mapper.Map <Contact, ContactVM>(this.BusinessRule.UnitOfWork.Repository <Contact>().Find(reservation.ContactID)),

                        ID = reservation.ID,
                        DisplayRegisterDate = reservation.DisplayRegisterDate,
                        ContactID           = reservation.ContactID,
                        OrganID             = reservation.OrganID,
                        RegisterDate        = reservation.RegisterDate,
                        ValiditDuration     = reservation.ValiditDuration,
                        ReservationDetails  = Reservation_DetailVMs
                    };

                    return(Request.CreateResponse(HttpStatusCode.OK, new { resualtCode = (int)ZhivarEnums.ResultCode.Successful, data = resualt }));
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }