Пример #1
0
        private bool GenerateTransaction(ItemOnhandModel line, double qty)
        {
            MaterialIssueModel Head = _view.head;

            ItemTransactionModel trans = new ItemTransactionModel();

            trans.InventoryItemId       = line.InventoryItemId;
            trans.SubinventoryCode      = line.SubinventoryCode;
            trans.TransactionSourceName = "MATERIAL ISSUE";
            trans.TransactionQuantity   = qty * -1;
            trans.TransactionUom        = string.IsNullOrEmpty(line.TransactionUomCode) ? "PCS" : line.TransactionUomCode;
            trans.PrimaryQuantity       = qty * -1;
            trans.TransactionDate       = Head.IssueDate;
            trans.TransactionReference  = Head.IssueNumber;
            //trans.TransactionSourceName
            trans.TransactionSourceId = line.OnhandQuantitiesId;        //Only Materail Issue using ONHAND_QUANTITIES_ID
            trans.CostedFlag          = "Y";
            trans.ActualCost          = line.TransactionUnitCost;
            trans.TransactionCost     = line.TransactionUnitCost;
            trans.Attribute1          = string.IsNullOrEmpty(line.IssueProjectNum) ? line.ProjectNum : line.IssueProjectNum;
            trans.Attribute2          = string.IsNullOrEmpty(line.IssueCostCode) ? line.ProjectCostCode : line.IssueCostCode;
            trans.Attribute3          = line.LotNumber;
            trans.Attribute4          = line.BomNo;

            int id = _repoTrans.InsertTrans(trans);

            ItemOnhandModel onhand = line;

            //if (onhand != null)
            //{

            double trxQty = onhand.PrimaryTransactionQuantity - qty;

            onhand.PrimaryTransactionQuantity = trxQty;
            onhand.TransactionQuantity        = trxQty;
            onhand.UpdateTransactionId        = id;
            onhand.TransactionUnitCost        = trans.ActualCost;

            _repoOnhand.UpdateOnhand(onhand);
            //}
            return(true);
        }
        private bool GenerateTransaction(IEnumerable <POReceiptLineModel> lines)
        {
            bool result = true;

            try
            {
                POReceiptHeaderModel recHead = _view.headSeleted;

                foreach (var recLine in lines)
                {
                    ItemTransactionModel trans = new ItemTransactionModel();
                    trans.InventoryItemId       = recLine.ItemId;
                    trans.SubinventoryCode      = recLine.ToSubinventory;
                    trans.TransactionSourceName = "PO RECEIVING";
                    trans.TransactionQuantity   = recLine.QuantityShipped;
                    trans.TransactionUom        = string.IsNullOrEmpty(recLine.UnitOfMeasure) ? "PCS" : recLine.UnitOfMeasure;
                    trans.PrimaryQuantity       = recLine.QuantityShipped;
                    trans.TransactionDate       = recHead.ReceiptDate;
                    trans.TransactionReference  = recHead.ReceiptNum;
                    trans.CostedFlag            = "Y";
                    trans.ActualCost            = recLine.ShipmentUnitPrice;
                    trans.TransactionCost       = recLine.ShipmentUnitPrice;
                    trans.Attribute1            = recLine.ProjectNum;
                    trans.Attribute2            = recLine.CostCode;
                    trans.Attribute3            = recLine.LotNumber;
                    trans.Attribute4            = recLine.Attribute1; //BOM No.
                    trans.TrxSourceLineId       = recLine.ReceiptLineId;
                    trans.TransferSubinventory  = recLine.ToSubinventory;

                    //Update po_line_id to task_id For PO line is Job Process.
                    if (recLine.QcRequireInspcFlag)
                    {
                        trans.TaskId = recLine.PoLineId;
                    }

                    int id = _repoTrans.InsertTrans(trans);

                    ItemOnhandModel onhand = _repoOnhand.GetDupplicated(recLine.ItemId
                                                                        , recLine.ToSubinventory
                                                                        , recLine.LotNumber
                                                                        , string.IsNullOrEmpty(recLine.Attribute1) ? "999" : recLine.Attribute1  //If BOM No. is null default '999'
                                                                        );
                    if (onhand != null)
                    {
                        double trxQty = onhand.PrimaryTransactionQuantity + recLine.QuantityShipped;
                        onhand.PrimaryTransactionQuantity = trxQty;
                        onhand.TransactionQuantity        = trxQty;
                        onhand.UpdateTransactionId        = id;
                        onhand.TransactionUnitCost        = recLine.ShipmentUnitPrice;

                        _repoOnhand.UpdateOnhand(onhand);
                    }
                    else
                    {
                        onhand = new ItemOnhandModel();
                        onhand.InventoryItemId            = recLine.ItemId;
                        onhand.DateReceived               = _view.headSeleted.RequestDate;
                        onhand.PrimaryTransactionQuantity = recLine.QuantityShipped;
                        onhand.TransactionQuantity        = recLine.QuantityShipped;
                        onhand.SubinventoryCode           = recLine.ToSubinventory;
                        onhand.LotNumber           = recLine.LotNumber;
                        onhand.TransactionUomCode  = recLine.UnitOfMeasure;
                        onhand.CreateTransactionId = id;
                        onhand.UpdateTransactionId = id;
                        onhand.BomNo = string.IsNullOrEmpty(recLine.Attribute1) ? "999" : recLine.Attribute1;  //If BOM No. is null default '999'
                        onhand.TransactionUnitCost = recLine.ShipmentUnitPrice;
                        onhand.ProjectId           = recLine.ProjectId;
                        onhand.ProjectNum          = recLine.ProjectNum;
                        onhand.ProjectCostCode     = recLine.CostCode;

                        //Update po_line_id to task_id For PO line is Job Process.
                        if (recLine.QcRequireInspcFlag)
                        {
                            onhand.TaskId = recLine.PoLineId;
                        }

                        int onhandId = _repoOnhand.InsertOnhand(onhand);
                    }
                }

                result = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Received process error : ." + Environment.NewLine + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                result = false;
            }
            return(result);
        }
        private void GenerateTransaction(ItemTransactionModel line, double qty, string returnNumber, DateTime transactionDate)
        {
            //MaterialIssueModel Head = _view.head;

            ItemTransactionModel trans = new ItemTransactionModel();

            trans.InventoryItemId       = line.InventoryItemId;
            trans.SubinventoryCode      = line.TransferSubinventory; //Source Subinventory
            trans.TransferSubinventory  = line.TransferSubinventory;
            trans.TransactionSourceName = "MATERIAL RETURN";
            trans.TransactionQuantity   = Math.Abs(qty);
            trans.TransactionUom        = line.TransactionUom;
            trans.PrimaryQuantity       = Math.Abs(qty);
            trans.TransactionDate       = transactionDate;
            trans.TransactionReference  = returnNumber;
            //trans.TransactionSourceName
            trans.TransactionSourceId = line.TransactionId;     //Only Materail Return using transaction_id
            trans.CostedFlag          = "Y";
            trans.ActualCost          = line.ActualCost;
            trans.TransactionCost     = line.TransactionCost;
            trans.Attribute1          = line.Attribute1;
            trans.Attribute2          = line.Attribute2;
            trans.Attribute3          = line.Attribute3;
            trans.Attribute4          = line.Attribute4;

            line.QuantityAdjusted    = line.QuantityAdjusted + qty;
            line.TransactionQuantity = line.TransactionQuantity * -1;
            line.LastUpdateDate      = DateTime.Now;
            line.LastUpdatedBy       = _view.EpiSession.User.Id;
            _repoTrans.UpdateTrans(line);

            int id = _repoTrans.InsertTrans(trans);

            ItemOnhandModel onhand = _repoOnhand.GetDupplicated(line.InventoryItemId
                                                                , line.TransferSubinventory
                                                                , line.Attribute3
                                                                , string.IsNullOrEmpty(line.Attribute4) ? "999" : line.Attribute4  /*Bom Number*/
                                                                );

            if (onhand != null)
            {
                double trxQty = onhand.PrimaryTransactionQuantity + qty;
                onhand.PrimaryTransactionQuantity = trxQty;
                onhand.TransactionQuantity        = trxQty;
                onhand.UpdateTransactionId        = id;
                onhand.TransactionUnitCost        = trans.ActualCost;

                _repoOnhand.UpdateOnhand(onhand);
            }
            else
            {
                onhand = new ItemOnhandModel();
                onhand.InventoryItemId            = line.InventoryItemId;
                onhand.DateReceived               = DateTime.Now;
                onhand.PrimaryTransactionQuantity = qty;
                onhand.TransactionQuantity        = qty;
                onhand.SubinventoryCode           = line.TransferSubinventory;
                onhand.LotNumber           = line.Attribute3;
                onhand.TransactionUomCode  = line.TransactionUom;
                onhand.CreateTransactionId = id;
                onhand.UpdateTransactionId = id;
                onhand.BomNo = string.IsNullOrEmpty(line.Attribute4) ? "999" : line.Attribute4;
                onhand.TransactionUnitCost = trans.ActualCost;
                //onhand.ProjectId = ;
                onhand.ProjectNum      = line.Attribute1;
                onhand.ProjectCostCode = line.Attribute2;

                int onhandId = _repoOnhand.InsertOnhand(onhand);
            }
        }