public async Task <IActionResult> NewBill(long typeId) { var billType = await _billTypeRepo.GetAsync(typeId); if (billType == null) { return(NotFound(Resources.Bills.BillResource.BillTypeNotFound)); } var newBill = new NewBillViewModel(); switch (billType.Type) { case BillsType.Transfer: return(BadRequest("can't not add new transfare from here!")); case BillsType.EndPeriodInventory: return(BadRequest("can't add End Period Inventory bill")); } #region billType properties newBill.BillTypeId = billType.Number; newBill.BillTypeName = billType.Name; newBill.ShowBranchField = billType.ShowBranchField; newBill.ShowCostCenterldField = billType.ShowCostCenterldField; newBill.ShowCustomerAccountldField = billType.ShowCustomerAccountldField; newBill.ShowDiscField = billType.ShowDiscField; newBill.ShowItemExpireDateField = billType.ShowItemExpireDateField; newBill.ShowExtraField = billType.ShowExtraField; newBill.ShowItemDiscField = billType.ShowItemDiscField; newBill.ShowItemExtraField = billType.ShowItemExtraField; newBill.ShowItemUnitField = billType.ShowItemUnitField; newBill.ShowItemCostCenterldField = billType.ShowItemCostCenterldField; newBill.ShowItemPriceFields = billType.ShowItemPriceFields; newBill.ShowItemStoreField = billType.ShowItemStoreField; newBill.ShowNoteField = billType.ShowNoteField; newBill.ShowItemNoteField = billType.ShowItemNoteField; newBill.ShowPayTypeField = billType.ShowPayTypeField; newBill.ShowItemProductionDateField = billType.ShowItemProductionDateField; newBill.ShowSellersFields = billType.ShowSellersFields; newBill.ShowStoreField = billType.ShowStoreField; newBill.ShowTotalPriceItemField = billType.ShowTotalPriceItemField; newBill.CanEditItemPrice = billType.CanEditItemPrice; newBill.CanEditItemTotalPrice = billType.CanEditItemTotalPrice; newBill.Color1 = billType.Color1; newBill.Color2 = billType.Color2; #endregion newBill.Number = await _billRepo.GetNextNumberAsync(billType.Id); #region default values newBill.PayType = billType.DefaultPayType; if (billType.DefaultPriceId.HasValue) { var price = await _priceRepo.FindAsync(billType.DefaultPriceId.Value); if (price != null) { newBill.PriceId = price.Number; newBill.PriceName = price.Name; } } if (billType.DefaultCurrencyId.HasValue) { var curency = await _currencyRepo.FindAsync(billType.DefaultCurrencyId.Value); if (curency != null) { newBill.CurrencyId = curency.Number; } } if (!newBill.CurrencyId.HasValue) { var curency = await _currencyRepo.FindAsync(_defaultKeysOptions.Value.CurrencyId); if (curency != null) { newBill.CurrencyId = curency.Number; } } if (billType.DefaultStoreId.HasValue) { var store = await _storeRepo.FindAsync(billType.DefaultStoreId.Value); if (store != null) { newBill.StoreId = store.Number; newBill.StoreCodeName = store.CodeName; } } if (billType.DefaultCashAccountId.HasValue) { var account = await _accountRepo.FindAsync(billType.DefaultCashAccountId.Value); if (account != null) { newBill.AccountId = account.Number; newBill.AccountCodeName = account.CodeName; } } if (billType.DefaultCostCenterId.HasValue) { var costCenter = await _costCenterRepo.FindAsync(billType.DefaultCostCenterId.Value); if (costCenter != null) { newBill.CostCenterId = costCenter.Number; newBill.CostCenterCodeName = costCenter.CodeName; } } if (billType.DefaultBranchId.HasValue) { var branch = await _branchRepo.FindAsync(billType.DefaultBranchId.Value); if (branch != null) { newBill.BranchId = branch.Number; newBill.BranchCodeName = branch.CodeName; } } #endregion return(Ok(newBill)); }