private static async Task <Guid> SaveInvoiceItem(ZubairEntities dbContext, int invoiceID, dynamic it, int billingItemId, Guid invoiceItemId, invoiceitem invoiceItem)
        {
            // update invoice items
            if (invoiceItem != null)
            {
                invoiceItem.invoice_id      = invoiceID;
                invoiceItem.billing_item_id = billingItemId;
                invoiceItem.discount        = it.Discount;
                invoiceItem.totalcost       = it.TotalCost;
                invoiceItem.taxes           = it.Taxes;
                invoiceItemId = invoiceItem.id;
                await dbContext.SaveChangesAsync();
            }
            else
            {
                // create invoice items
                var tempInvoiceItem = new invoiceitem
                {
                    id              = Guid.NewGuid(),
                    invoice_id      = invoiceID,
                    billing_item_id = billingItemId,
                    discount        = it.Discount,
                    totalcost       = it.TotalCost
                };

                dbContext.invoiceitems.Add(tempInvoiceItem);
                await dbContext.SaveChangesAsync();

                dbContext.Entry(tempInvoiceItem).GetDatabaseValues();
                invoiceItemId = tempInvoiceItem.id;
            }

            return(invoiceItemId);
        }
        public async Task <(bool IsSuccess, string ErrorMessage)> UpdateInvoiceItem(InvoiceItem invoiceItem)
        {
            try
            {
                using (ZubairEntities dbContext = new ZubairEntities())
                {
                    var tempInvoice = await dbContext.invoiceitems.Where(c => c.id == invoiceItem.Id).FirstOrDefaultAsync();

                    if (tempInvoice != null)
                    {
                        var tempInvoiceItem = new invoiceitem();
                        tempInvoiceItem.invoice_id      = invoiceItem.InvoiceId;
                        tempInvoiceItem.billing_item_id = invoiceItem.BillingItemId;
                        tempInvoiceItem.discount        = invoiceItem.Discount;
                        tempInvoiceItem.totalcost       = invoiceItem.TotalCost;
                        await dbContext.SaveChangesAsync();

                        return(true, null);
                    }
                }
                return(false, "Not Found");
            }
            catch (Exception ex)
            {
                //logger?.LogError(ex.ToString());
                return(false, ex.Message);
            }
        }
        public async Task <(bool IsSuccess, string ErrorMessage)> CreateInvoiceItem(InvoiceItem invoiceItem)
        {
            try
            {
                using (ZubairEntities dbContext = new ZubairEntities())
                {
                    if (invoiceItem != null)
                    {
                        var tempInvoiceItem = new invoiceitem();
                        tempInvoiceItem.id              = Guid.NewGuid();
                        tempInvoiceItem.invoice_id      = invoiceItem.InvoiceId;
                        tempInvoiceItem.billing_item_id = invoiceItem.BillingItemId;
                        tempInvoiceItem.discount        = invoiceItem.Discount;
                        tempInvoiceItem.totalcost       = invoiceItem.TotalCost;
                        dbContext.invoiceitems.Add(tempInvoiceItem);
                        await dbContext.SaveChangesAsync();

                        return(true, null);
                    }
                }
                return(false, "Not Found");
            }
            catch (Exception ex)
            {
                //logger?.LogError(ex.ToString());
                return(false, ex.Message);
            }
        }
Esempio n. 4
0
 public IHttpActionResult UpdateItem(int id, invoiceitem data)
 {
     //id is invoice id
     try
     {
         if (data == null)
         {
             throw new SystemException("Periksa Kembali Data Anda");
         }
         return(Ok(context.UpdateItem(id, data)));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Esempio n. 5
0
        public object Getitems(int id)
        {
            using (var db = new OcphDbContext())
            {
                try
                {
                    IEnumerable <price> prices = db.Prices.Where(x => x.AgentId == id);
                    var command = db.CreateCommand();
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.CommandText = "SttNotPaid";
                    command.Parameters.Add(new MySql.Data.MySqlClient.MySqlParameter("id", id));
                    var result = command.ExecuteReader();
                    var datas  = Ocph.DAL.Mapping.MySql.MappingProperties <stt> .MappingTable(result);

                    var list = new List <invoiceitem>();


                    if (datas != null)
                    {
                        foreach (var data in datas)
                        {
                            if (data.Id > 0)
                            {
                                var dataprice = prices.Where(x => x.CityId == data.CityId && x.PortType == data.ShippingBy).FirstOrDefault();

                                var item = new invoiceitem {
                                    STT = data, STTId = data.Id
                                };
                                item.Price = dataprice == null ? 0 : dataprice.PriceValue;
                                list.Add(item);
                            }
                        }
                        return(list);
                    }

                    throw new SystemException("Data Tidak Ada");
                }
                catch (Exception ex)
                {
                    throw new SystemException(ex.Message);
                }
            }
        }
Esempio n. 6
0
        public invoiceitem UpdateItem(int id, invoiceitem data)
        {
            using (var db = new OcphDbContext())
            {
                try
                {
                    var invoice = db.Invoices.Where(O => O.Id == id).FirstOrDefault();
                    if (invoice != null)
                    {
                        var updated = db.InvoiceItems.Update(O => new { O.OtherCosts, O.Price }, data, O => O.Id == data.Id);
                        if (updated)
                        {
                            return(data);
                        }
                    }

                    throw new SystemException();
                }
                catch (Exception)
                {
                    throw new SystemException("Invoice Item Gagal Ditambah");
                }
            }
        }