Exemple #1
0
        private void btnExport_Click_1(object sender, EventArgs e)
        {
            StringBuilder csv = new StringBuilder();

            foreach (var row in ReportResult)
            {
                Enums.UnitTypes types   = (Enums.UnitTypes)row.Unit;
                string          unit    = types.ToString();
                var             newLine = string.Format("{0},{1},{2},{3},{4}", row.Date, row.PriceEach, row.Quantity, unit,
                                                        row.Total);
                csv.AppendLine(newLine);
            }
            File.WriteAllText(Settings.Default.InvoiceSaveLocation + @"\csv.csv", csv.ToString());
        }
        private async void LoadDataFromDb()
        {
            CommonWarehouseReceipt receipt = await SASale.GetReceipt(Sale.SaleId);

            mlLabel17.Text = receipt.BuyerCompanyName;
            mlLabel15.Text = receipt.BuyerVATNumber;
            mlLabel13.Text = receipt.BuyerBulstat;
            mlLabel7.Text  = receipt.BuyerMol;
            labelMolS.Text = receipt.BuyerMol;
            mlLabel9.Text  = receipt.BuyerAddress;
            labelSalesReceiptNumber.Text = receipt.WarehouseReceiptNumber.ToString().PadLeft(10, '0');
            mlLabelSalesReceiptDate.Text = Sale.Date.ToString(CultureInfo.InvariantCulture);
            mlLabel24.Text        = receipt.OwnerCompanyName;
            mlLabel23.Text        = receipt.OwnerVATNumber;
            mlLabel22.Text        = receipt.OwnerBulstat;
            mlLabel21.Text        = receipt.OwnerAddress;
            mlLabel20.Text        = receipt.OwnerMol;
            labelSuplierMolS.Text = receipt.OwnerMol;


            decimal totalBoth   = 0;
            decimal ddsTotal    = 0;
            decimal totatAmount = 0;


            List <GridItem> items = new List <GridItem>();

            foreach (var soldItem in Sale.SoldItems)
            {
                CommonItem item = await SAItem.GetItemsById(soldItem.ItemId.ToString());

                if (item != null)
                {
                    GridItem gridItem = new GridItem();
                    gridItem.Name     = item.Name;
                    gridItem.Quantity = soldItem.Quantity.ToString();
                    if (DataHolder.UserCulture.TwoLetterISOLanguageName == "bg")
                    {
                        Enums.UnitTypesBg types = (Enums.UnitTypesBg)item.MeasurmentUnit;
                        gridItem.MeasurementUnitString = types.ToString();
                    }
                    else
                    {
                        Enums.UnitTypes types = (Enums.UnitTypes)item.MeasurmentUnit;
                        gridItem.MeasurementUnitString = types.ToString();
                    }
                    decimal temp = item.SellingPriceCent;
                    gridItem.Price = temp / 100;
                    var vatPercent = DataHolder.Settings.VatSettingsByGroup.FirstOrDefault(p => p.Key == item.Type);
                    gridItem.Total = soldItem.Quantity * gridItem.Price;
                    items.Add(gridItem);

                    totatAmount += gridItem.Price * soldItem.Quantity;
                    ddsTotal    += (gridItem.Price * soldItem.Quantity) * vatPercent.Value;
                    totalBoth   += (gridItem.Price * soldItem.Quantity) + ((gridItem.Price * soldItem.Quantity) * vatPercent.Value);
                }
            }
            dgvItemsS.DataSource = items;
            labelAmountS.Text    = totatAmount.ToString();
            labelTotalS.Text     = totalBoth.ToString();
            labelDDSS.Text       = ddsTotal.ToString();

            // do not change set grid size and export method order!
            SetGridSize();
            if (SavePdf)
            {
                ExportInvoiceToPdf();
            }
        }
        public async void LoadDataAsync()
        {
            try
            {
                if (Settings.Default.ItemMapping)
                {
                    List <KeyValuePair <Guid, List <CommonItem> > > results = await SAItem.GetAllItemsMapped();

                    foreach (var kvp in results)
                    {
                        foreach (var row in kvp.Value)
                        {
                            if (DataHolder.UserCulture.TwoLetterISOLanguageName == "bg")
                            {
                                Enums.UnitTypesBg types = (Enums.UnitTypesBg)row.MeasurmentUnit;
                                row.MeasurmentUnitString = types.ToString();
                            }
                            else
                            {
                                Enums.UnitTypes types = (Enums.UnitTypes)row.MeasurmentUnit;
                                row.MeasurmentUnitString = types.ToString();
                            }
                        }
                    }
                    MappedItems = results;
                    cbSearchGoodsOrders.DropDownStyle      = ComboBoxStyle.DropDown;
                    cbSearchGoodsOrders.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
                    cbSearchGoodsOrders.AutoCompleteSource = AutoCompleteSource.ListItems;
                }
                else
                {
                    AllItems = await SAItem.GetAllItems(cbSearchGoodsOrders.Text);

                    List <CommonItem> k = new List <CommonItem>();

                    foreach (CommonItem Item in AllItems)
                    {
                        decimal temp = Item.SellingPriceCent;
                        Item.ParcePrice = temp / 100;
                        if (DataHolder.UserCulture.TwoLetterISOLanguageName == "bg")
                        {
                            Enums.UnitTypesBg types = (Enums.UnitTypesBg)Item.MeasurmentUnit;
                            Item.MeasurmentUnitString = types.ToString();
                        }
                        else
                        {
                            Enums.UnitTypes types = (Enums.UnitTypes)Item.MeasurmentUnit;
                            Item.MeasurmentUnitString = types.ToString();
                        }
                    }
                }

                cbSearchGoodsOrders.DataSource         = AllItems;
                cbSearchGoodsOrders.SelectedIndex      = -1;
                cbSearchGoodsOrders.DropDownStyle      = ComboBoxStyle.DropDown;
                cbSearchGoodsOrders.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
                cbSearchGoodsOrders.AutoCompleteSource = AutoCompleteSource.ListItems;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, DataHolder.GetString("error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #4
0
        private async void btnGenerate_Click_1(object sender, EventArgs e)
        {
            bool trigger = true;

            if (rbSpecificItem.Checked)
            {
                if (string.IsNullOrWhiteSpace(tbSpecificItem.Text))
                {
                    labelError.Text    = "invalid_data";
                    labelError.Visible = true;
                    trigger            = false;
                }
            }
            if (trigger)
            {
                labelError.Visible = false;
                int item;
                int report;
                if (DataHolder.UserCulture.TwoLetterISOLanguageName == "bg")
                {
                    Enums.ReportTypeBg reportType;
                    Enum.TryParse(cbReportType.SelectedValue.ToString(), out reportType);
                    report = (int)reportType;
                    Enums.ItemTypesBg itemType;
                    Enum.TryParse(cbItemType.SelectedValue.ToString(), out itemType);
                    item = (int)itemType;
                }
                else
                {
                    Enums.ReportType reportType;
                    Enum.TryParse(cbReportType.SelectedValue.ToString(), out reportType);
                    report = (int)reportType;
                    Enums.ItemTypes itemType;
                    Enum.TryParse(cbItemType.SelectedValue.ToString(), out itemType);
                    item = (int)itemType;
                }
                ReportDTO dto = new ReportDTO();
                dto.FromDate   = dtFrom.Value;
                dto.ToDate     = dtTo.Value;
                dto.IsItem     = rbSpecificItem.Checked;
                dto.IsType     = rbItemType.Checked;
                dto.ItemCode   = tbSpecificItem.Text;
                dto.ItemType   = item;
                dto.ReportType = report;

                List <ReportBuySell> result = await SAReports.PostGenerateReport(dto);

                if (result.Count == 0)
                {
                    labelError.Text       = "no_results_found";
                    labelError.Visible    = true;
                    dgvResults.DataSource = null;
                    CheckButtonState();
                }
                else
                {
                    if (DataHolder.UserCulture.TwoLetterISOLanguageName == "bg")
                    {
                        foreach (var row in result)
                        {
                            Enums.UnitTypesBg types = (Enums.UnitTypesBg)row.Unit;
                            row.UnitString = types.ToString();
                        }
                    }
                    else
                    {
                        foreach (var row in result)
                        {
                            Enums.UnitTypes types = (Enums.UnitTypes)row.Unit;
                            row.UnitString = types.ToString();
                        }
                    }

                    foreach (var row in result)
                    {
                        row.PriceEach = row.PriceEach / 100;
                        row.Total     = row.Total / 100;
                    }
                    dgvResults.DataSource = result;
                    ReportResult          = result;
                    CheckButtonState();
                }
            }
        }