Exemplo n.º 1
0
        private void insertAndCalculateDO(MutasiOrder transactionApi)
        {
            //Remark Sementara
            //for (int i = 0; i < transactionApi.mutasiOrderLines.Count; i++)
            //{
            //    InventoryLines inventoryLines = _context.InventoryLines.Where(c => c.WarehouseId == transactionApi.mutasiFromWarehouse && c.ItemId == transactionApi.mutasiOrderLines[i].article.id).First();
            //    InventoryTransactionLines transaction = new InventoryTransactionLines();
            //    transaction.TransactionTypeId = RetailEnum.MutasiOrderOut;
            //    transaction.TransactionTypeName = "Mutasi Out";
            //    transaction.TransRefId = transactionApi.mutasiOrderId;
            //    transaction.Qty = -1 * transactionApi.mutasiOrderLines[i].quantity;
            //    transaction.TransactionLinesId = inventoryLines.Id;
            //    transaction.TransactionDate = DateTime.Now;//DateTime.ParseExact(transactionApi.date, "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);

            //    _context.Add(transaction);
            //    _context.SaveChanges();

            //    //update qty
            //    inventoryLines.Qty = _context.InventoryTransactionLines.
            //                         Where(c => c.TransactionLinesId == inventoryLines.Id)
            //                        .Select(c => c.Qty)
            //                        .DefaultIfEmpty()
            //                        .Sum();
            //    _context.InventoryLines.Update(inventoryLines);
            //    _context.SaveChanges();
            //}
        }
Exemplo n.º 2
0
        private void sequenceNumber(MutasiOrder transactionApi)
        {
            SequenceNumberLog log = new SequenceNumberLog();

            log.StoreCode          = transactionApi.storeCode;
            log.LastNumberSequence = transactionApi.sequenceNumber;
            log.LastTransId        = transactionApi.mutasiOrderId;
            log.Date            = DateTime.Now;
            log.TransactionType = "Mutasi Order";
            _context.SequenceNumberLog.Add(log);
            _context.SaveChanges();
        }
Exemplo n.º 3
0
        public IActionResult getMutasi(String StoreCode)
        {
            List <InventoryTransactionLines> listtransline = _context.InventoryTransactionLines.ToList();
            List <Item>                 listitem           = _context.Item.ToList();
            List <MutasiOrder>          deliveryOrders     = new List <MutasiOrder>();
            List <InventoryTransaction> dos = _context.InventoryTransaction.Where(c => c.WarehouseOriginal == StoreCode && c.TransactionTypeId == RetailEnum.MutasiOrderOut && c.InforBypass == true).ToList();

            foreach (InventoryTransaction intrans in dos)
            {
                // tambah ini

                InventoryTransaction inventory = intrans;
                //========
                //Select For Header
                MutasiOrder doObj = new MutasiOrder
                {
                    date          = DateTime.Now.ToString("yyyy-MM-dd"),
                    id            = inventory.Id,
                    mutasiOrderId = inventory.TransactionId,

                    status              = inventory.StatusId.HasValue ? inventory.StatusId.Value : 0,
                    totalQty            = inventory.TotalQty.HasValue ? inventory.TotalQty.Value : 0,
                    mutasiFromWarehouse = inventory.WarehouseOriginal,
                    mutasiToWarehouse   = inventory.WarehouseDestination,
                    isPbmPbk            = inventory.InforBypass.HasValue ? inventory.InforBypass.Value : false,
                    totalAmount         = _context.InventoryTransactionLines.Where(c => c.InventoryTransactionId == inventory.Id).Sum(d => d.ValueSalesPrice),
                };

                List <MutasiOrderLine> deliveryOrderLines = new List <MutasiOrderLine>();
                int sumLines = 0;
                //  List<InventoryTransactionLines> dosLines = _context.InventoryTransactionLines.Where(c => c.InventoryTransactionId == intrans.Id).ToList();
                List <InventoryTransactionLines> dosLines = _context.InventoryTransactionLines.Where(c => c.InventoryTransactionId == inventory.Id).ToList();


                foreach (InventoryTransactionLines doObjLines in dosLines)
                {
                    //
                    int idx2 = indexttransline(doObjLines.Id, listtransline);
                    InventoryTransactionLines invenlines = listtransline[idx2];
                    int  idx3 = indextitems(invenlines.ArticleId, listitem);
                    Item item = listitem[idx3];



                    MutasiOrderLine doLine = new MutasiOrderLine
                    {
                        id      = invenlines.Id,
                        article = new Article
                        {
                            articleId      = item.ItemId,
                            articleIdAlias = item.ItemIdAlias,
                            articleName    = invenlines.ArticleName
                        },
                        articleIdFk     = item.Id,
                        mutasiOrderIdFk = inventory.Id,
                        mutasiOrderId   = inventory.TransactionId,
                        quantity        = invenlines.Qty.Value
                    };
                    deliveryOrderLines.Add(doLine);
                }

                doObj.totalQty         = inventory.TotalQty.Value;
                doObj.mutasiOrderLines = deliveryOrderLines;
                deliveryOrders.Add(doObj);
            }
            return(Ok(deliveryOrders));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> PostTransaction([FromBody] MutasiOrder transactionApi)
        {
            APIResponse response = new APIResponse();

            try
            {
                if (transactionApi.mutasiFromWarehouse == "" || transactionApi.mutasiFromWarehouse == null || transactionApi.mutasiToWarehouse == "" || transactionApi.mutasiFromWarehouse == null)
                {
                    response.code    = "0";
                    response.message = "No Warehouse Origin / Destination, Make sure to fill it.";
                    return(BadRequest(response));
                }
                bool exist = _context.InventoryTransaction.Any(c => c.TransactionId == transactionApi.mutasiOrderId);
                if (exist == false)
                {
                    LogRecord log = new LogRecord();
                    log.TimeStamp     = DateTime.Now;
                    log.Tag           = "Mutasi Order";
                    log.Message       = JsonConvert.SerializeObject(transactionApi);
                    log.TransactionId = transactionApi.mutasiOrderId;
                    await _context.LogRecord.AddAsync(log);

                    await _context.SaveChangesAsync();

                    DateTime asd;// = DateTime.Now;
                    try
                    {
                        // transaction.RequestDeliveryDate = DateTime.ParseExact(transactionApi.timeStamp, "MMM dd, yyyy h:mm:ss tt", CultureInfo.InvariantCulture);
                        asd = DateTime.ParseExact(transactionApi.date, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                    }
                    catch
                    {
                        asd = DateTime.ParseExact(transactionApi.date, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                    }
                    DateTime maret10 = DateTime.ParseExact("2019-03-10", "yyyy-MM-dd", CultureInfo.InvariantCulture);
                    if (maret10 >= asd)
                    {
                        response.code    = "1";
                        response.message = "Sucess Add Data";
                        return(Ok(response));
                    }

                    Store store = _context.Store.Where(c => c.Code == transactionApi.storeCode).First();
                    Models.InventoryTransaction transaction = new Models.InventoryTransaction();
                    transaction.TransactionId       = transactionApi.mutasiOrderId;
                    transaction.StoreCode           = transactionApi.storeCode;
                    transaction.Remarks             = transactionApi.remarks;
                    transaction.StoreName           = store.Name;
                    transaction.TransactionTypeId   = RetailEnum.mutasiTransaction;
                    transaction.TransactionTypeName = "Mutasi";
                    transaction.Status               = null;
                    transaction.StatusId             = null;
                    transaction.WarehouseOriginal    = transactionApi.mutasiFromWarehouse;
                    transaction.WarehouseDestination = transactionApi.mutasiToWarehouse;
                    transaction.RequestDeliveryDate  = DateTime.Now;
                    transaction.Sjlama               = transactionApi.oldSJ;
                    transaction.TransactionDate      = DateTime.Now;//DateTime.ParseExact(transactionApi.date, "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                    try
                    {
                        transaction.TransactionDate = DateTime.Parse(transactionApi.date);
                    }
                    catch
                    {
                    }
                    try
                    {
                        transaction.RequestDeliveryDate = DateTime.Parse(transactionApi.requestDeliveryDate);
                    }
                    catch
                    {
                    }
                    transaction.TotalQty = transactionApi.totalQty;
                    transaction.Remarks  = "";
                    try
                    {
                        transaction.EmployeeCode = transactionApi.employeeId;
                        transaction.EmployeeName = transactionApi.employeeName;
                    }
                    catch
                    {
                    }
                    //add by frank for mutasi matrix
                    try
                    {
                        Store storeMaster = _context.Store.Where(c => c.Code == transactionApi.mutasiFromWarehouse).First();
                        List <MutasiApproverMatrix> mutasiApproverMatrixs = _context.MutasiApproverMatrix.Where(c => c.StoreMatrix == storeMaster.Id).ToList();
                        MutasiApproverMatrix        ms = mutasiApproverMatrixs.Where(c => c.StoreMatrix == storeMaster.Id).First();
                        if (transactionApi.mutasiType == 1)
                        {
                            transaction.EmployeeToApprove = ms.ApproverCity;
                        }
                        else if (transactionApi.mutasiType == 2)
                        {
                            transaction.EmployeeToApprove = ms.ApproverRegional;
                        }
                        else
                        {
                            transaction.EmployeeToApprove = ms.ApproverNational;
                        }
                    }
                    catch
                    {
                        transaction.EmployeeToApprove = "admin123";
                    }

                    if (!ModelState.IsValid)
                    {
                        return(BadRequest(ModelState));
                    }
                    //log record

                    _context.InventoryTransaction.Add(transaction);
                    _context.SaveChanges();

                    //save Lines
                    for (int i = 0; i < transactionApi.mutasiOrderLines.Count; i++)
                    {
                        Models.InventoryTransactionLines transactionLines = new Models.InventoryTransactionLines();
                        transactionLines.InventoryTransactionId = transaction.Id;
                        transactionLines.ArticleId   = transactionApi.mutasiOrderLines[i].article.articleIdAlias;
                        transactionLines.ArticleName = transactionApi.mutasiOrderLines[i].article.articleName;
                        transactionLines.Qty         = transactionApi.mutasiOrderLines[i].quantity;
                        try
                        {
                            transactionLines.ValueSalesPrice = transactionLines.Qty * _context.PriceList.Where(c => c.ItemId == transactionLines.ArticleId).First().SalesPrice;
                        }
                        catch
                        {
                            transactionLines.ValueSalesPrice = 0;
                        }
                        _context.InventoryTransactionLines.Add(transactionLines);
                        _context.SaveChanges();
                    }

                    response.code    = "1";
                    response.message = "Sucess Add Data";
                    //Duplace karena di POS sudah kurang, jika rect qty akan bertambah, jika approve tidak perlu kalkulaso
                    this.insertAndCalculateDO(transactionApi);
                    this.sequenceNumber(transactionApi);
                }
                else
                {
                    response.code    = "1";
                    response.message = "Transaction Already Exist";
                    LogRecord log = new LogRecord();
                    log.TimeStamp = DateTime.Now;
                    log.Tag       = "Mutasi Order";
                    log.Message   = transactionApi.mutasiOrderId + "Aleader Exist";
                    _context.LogRecord.Add(log);
                    _context.SaveChanges();
                }
            }

            catch (Exception ex)
            {
                response.code    = "1";
                response.message = ex.ToString();
            }


            // await _context.SaveChangesAsync();
            return(Ok(response));
            //     return CreatedAtAction("GetTransaction", new { id = transaction.Id }, transaction);
        }
Exemplo n.º 5
0
        //===============================================================================================

        public async Task <Boolean> mutasiOrder()
        {
            bool isSuccess = false;

            try
            {
                List <MutasiOrderLine> mo_LinesList = new List <MutasiOrderLine>();

                link_api = link.aLink;
                ckon.sqlCon().Open();

                String cmd = "SELECT a.MUTASI_ORDER_ID, a.STORE_CODE, a.DATE, a._id as MoId, a.MUTASI_FROM_WAREHOUSE, a.MUTASI_TO_WAREHOUSE, "
                             + "a.REQUEST_DELIVERY_DATE, a.STATUS, a.TIME, a.TIME_STAMP, a.TOTAL_QTY, a.EMPLOYEE_ID, a.EMPLOYEE_NAME, a.NO_SJ, "
                             + "c._id as ArtId, c.ARTICLE_ID, c.ARTICLE_NAME, c.UNIT, c.PRICE, c.ARTICLE_ID_ALIAS, b._id as MoLineId, b.QUANTITY FROM mutasiorder a INNER JOIN mutasiorder_line b "
                             + "ON a.MUTASI_ORDER_ID = b.MUTASI_ORDER_ID INNER JOIN article c "
                             + "ON c.ARTICLE_ID = b.ARTICLE_ID WHERE a.STATUS_API = 0";

                ckon.sqlDataRd = sql.ExecuteDataReader(cmd, ckon.sqlCon());
                if (ckon.sqlDataRd.HasRows)
                {
                    while (ckon.sqlDataRd.Read())
                    {
                        id_m_o2 = Convert.ToString(ckon.sqlDataRd["MUTASI_ORDER_ID"]);
                        seq_number_substring = id_m_o2.Substring(12);
                        store_code2          = Convert.ToString(ckon.sqlDataRd["STORE_CODE"]);
                        date2         = Convert.ToString(ckon.sqlDataRd["DATE"]);
                        id_Mo2        = Convert.ToInt32(ckon.sqlDataRd["MoId"]);
                        mut_from_war2 = Convert.ToString(ckon.sqlDataRd["MUTASI_FROM_WAREHOUSE"]);
                        mut_to_war2   = Convert.ToString(ckon.sqlDataRd["MUTASI_TO_WAREHOUSE"]);
                        req_dev_date2 = Convert.ToString(ckon.sqlDataRd["REQUEST_DELIVERY_DATE"]);
                        status2       = Convert.ToInt32(ckon.sqlDataRd["STATUS"]);
                        time2         = Convert.ToString(ckon.sqlDataRd["TIME"]);
                        timestamp2    = Convert.ToString(ckon.sqlDataRd["TIME_STAMP"]);
                        totalqty2     = Convert.ToInt32(ckon.sqlDataRd["TOTAL_QTY"]);
                        epy_id        = Convert.ToString(ckon.sqlDataRd["EMPLOYEE_ID"]);
                        epy_name      = Convert.ToString(ckon.sqlDataRd["EMPLOYEE_NAME"]);
                        no_sj         = Convert.ToString(ckon.sqlDataRd["NO_SJ"]);

                        id_article2      = Convert.ToInt32(ckon.sqlDataRd["ArtId"]);
                        id_from_article2 = Convert.ToString(ckon.sqlDataRd["ARTICLE_ID"]);
                        articleName2     = Convert.ToString(ckon.sqlDataRd["ARTICLE_NAME"]);
                        unit2            = Convert.ToString(ckon.sqlDataRd["UNIT"]);
                        price_article2   = Convert.ToInt32(ckon.sqlDataRd["PRICE"]);
                        art_id_alias     = Convert.ToString(ckon.sqlDataRd["ARTICLE_ID_ALIAS"]);

                        id_article_Fk2 = id_article2;
                        id_MO_Line2    = Convert.ToInt32(ckon.sqlDataRd["MoLineId"]);
                        qty2           = Convert.ToInt32(ckon.sqlDataRd["QUANTITY"]);

                        MutasiOrderLine mo_line = new MutasiOrderLine()
                        {
                            article = new Article
                            {
                                articleId      = id_from_article2,
                                articleName    = articleName2,
                                unit           = unit2,
                                id             = id_article2,
                                price          = price_article2,
                                articleIdAlias = art_id_alias
                            },
                            articleIdFk     = id_article_Fk2,
                            id              = id_MO_Line2,
                            mutasiOrderId   = id_m_o2,
                            mutasiOrderIdFk = id_Mo2,
                            quantity        = qty2,
                            unit            = unit2
                        };
                        mo_LinesList.Add(mo_line);
                    }

                    MutasiOrder mo_new = new MutasiOrder()
                    {
                        storeCode           = store_code2,
                        sequenceNumber      = seq_number_substring,
                        date                = date2,
                        id                  = id_Mo2,
                        mutasiFromWarehouse = mut_from_war2,
                        mutasiToWarehouse   = mut_to_war2,
                        mutasiOrderId       = id_m_o2,
                        mutasiOrderLines    = mo_LinesList,
                        requestDeliveryDate = req_dev_date2,
                        status              = status2,
                        time                = time2,
                        timeStamp           = timestamp2,
                        totalQty            = totalqty2,
                        employeeId          = epy_id,
                        employeeName        = epy_name,
                        oldSJ               = no_sj
                    };

                    var mutasiOrder = JsonConvert.SerializeObject(mo_new);
                    var credentials = new NetworkCredential("username", "password");
                    var handler     = new HttpClientHandler {
                        Credentials = credentials
                    };
                    var httpContent = new StringContent(mutasiOrder, Encoding.UTF8, "application/json");
                    using (var client = new HttpClient(handler))
                    {
                        try
                        {
                            HttpResponseMessage message = client.PostAsync(link_api + "/api/MutasiOrder", httpContent).Result;
                            if (message.IsSuccessStatusCode)
                            {
                                String cmd_update = "UPDATE mutasiorder SET STATUS_API = '1' WHERE MUTASI_ORDER_ID='" + id_m_o2 + "'";
                                CRUD   update     = new CRUD();
                                update.ExecuteNonQuery(cmd_update);

                                isSuccess = true;
                            }
                            else
                            {
                                isSuccess = false;
                                MessageBox.Show("Failed! Please try again.");
                            }
                        }
                        catch (Exception ex)
                        {
                            isSuccess = false;
                            MessageBox.Show(ex.ToString());
                        }
                    }
                }

                return(isSuccess);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());

                return(isSuccess);
            }
        }