Example #1
0
        private void frmWBReturnDetOut_Load(object sender, EventArgs e)
        {
            WHComboBox.Properties.DataSource = DBHelper.WhList;

            int wh_id = _wb.WaybillMove != null ? _wb.WaybillMove.SourceWid : 0;

            MatComboBox.Properties.DataSource = _db.WhMatGet(0, wh_id, _ka_id, DBHelper.ServerDateTime(), 0, "*", 0, "", DBHelper.CurrentUser.UserId, 0).ToList();


            if (_wb.WType == 4)
            {
                WHComboBox.Enabled = false;
                WhEditBtn.Enabled  = false;
            }

            if (_PosId == null)
            {
                _wbd = new WaybillDet()
                {
                    WbillId  = _wb.WbillId,
                    Amount   = 0,
                    OnValue  = _wb.OnValue,
                    WId      = _wb.WaybillMove != null ? (int?)_wb.WaybillMove.SourceWid : null,
                    Discount = 0,
                    Nds      = _wb.Nds
                };
            }
            else
            {
                _wbd = _db.WaybillDet.Find(_PosId);
            }

            if (_wbd != null)
            {
                WaybillDetBS.DataSource = _wbd;

                if (_db.Entry <WaybillDet>(_wbd).State == EntityState.Unchanged)
                {
                    var w_mat_turn = _db.WMatTurn.Where(w => w.SourceId == _wbd.PosId).ToList();
                    if (w_mat_turn.Count > 0)
                    {
                        _db.WMatTurn.RemoveRange(w_mat_turn);
                        _db.SaveChanges();
                    }

                    GetContent();

                    foreach (var item in w_mat_turn)
                    {
                        if (pos_in.Any(a => a.PosId == item.PosId))
                        {
                            pos_in.FirstOrDefault(a => a.PosId == item.PosId).Amount = item.Amount;
                        }
                    }
                }
            }

            GetOk();
        }
Example #2
0
        static public void ShowMatListByWH(BaseEntities db, WaybillList wb, DiscCards disc_card = null)
        {
            var f = new frmWhCatalog(1, disc_card);

            //   f.uc.xtraTabPage3.PageVisible = false;
            f.uc.xtraTabPage4.PageVisible             = false;
            f.uc.xtraTabPage5.PageVisible             = false;
            f.uc.xtraTabPage9.PageVisible             = false;
            f.uc.xtraTabPage11.PageVisible            = false;
            f.uc.MatListTabPage.PageVisible           = true;
            f.uc.xtraTabControl1.SelectedTabPageIndex = 4;
            f.uc.wb        = wb;
            f.uc.isMatList = true;

            if (f.ShowDialog() == DialogResult.OK)
            {
                var num = wb.WaybillDet.Count();
                foreach (var item in f.uc.custom_mat_list)
                {
                    var wbd = new WaybillDet
                    {
                        WbillId      = wb.WbillId,
                        Num          = ++num,
                        OnDate       = wb.OnDate,
                        MatId        = item.MatId,
                        WId          = item.WId,
                        Amount       = item.Amount,
                        Price        = item.Price - (item.Price * item.Discount / 100),
                        PtypeId      = item.PTypeId,
                        Discount     = item.Discount,
                        Nds          = wb.Nds,
                        CurrId       = wb.CurrId,
                        OnValue      = wb.OnValue,
                        BasePrice    = item.Price + Math.Round(item.Price.Value * wb.Nds.Value / 100, 2),
                        PosKind      = 0,
                        PosParent    = 0,
                        DiscountKind = disc_card != null ? 2 : 0,
                    };
                    db.WaybillDet.Add(wbd);
                    db.SaveChanges();

                    if (wb.WType == 16)
                    {
                        db.WMatTurn.Add(new WMatTurn()
                        {
                            SourceId = wbd.PosId,
                            PosId    = wbd.PosId,
                            WId      = wbd.WId.Value,
                            MatId    = wbd.MatId,
                            OnDate   = wbd.OnDate.Value,
                            TurnType = 3,
                            Amount   = wbd.Amount
                        });
                    }
                }
                db.SaveChanges();
            }
        }
Example #3
0
        private void AddMat(int mat_id)
        {
            var mat = _db.WaybillDet.FirstOrDefault(w => w.MatId == mat_id && w.WbillId == wb.WbillId);

            if (mat == null)
            {
                var p_type    = (wb.Kontragent != null ? (wb.Kontragent.PTypeId ?? DB.SkladBase().PriceTypes.First(w => w.Def == 1).PTypeId) : DB.SkladBase().PriceTypes.First(w => w.Def == 1).PTypeId);
                var mat_price = DB.SkladBase().GetListMatPrices(mat_id, wb.CurrId, p_type).FirstOrDefault();

                var discount     = _db.GetDiscount(wb.KaId, mat_id).FirstOrDefault();
                var remain_in_wh = _db.MatRemainByWh(mat_id, 0, 0, DateTime.Now, "*", DBHelper.CurrentUser.UserId).ToList();
                var price        = mat_price != null ? (mat_price.Price ?? 0) : 0;

                var num = wb.WaybillDet.Count();
                var wbd = new WaybillDet
                {
                    WbillId      = wb.WbillId,
                    Num          = ++num,
                    OnDate       = wb.OnDate,
                    MatId        = mat_id,
                    WId          = remain_in_wh.Any() ? remain_in_wh.First().WId : (DBHelper.WhList.Any(w => w.Def == 1) ? DBHelper.WhList.FirstOrDefault(w => w.Def == 1).WId : DBHelper.WhList.FirstOrDefault().WId),
                    Amount       = 1,
                    Price        = price - (price * (discount ?? 0.00m) / 100),
                    PtypeId      = mat_price != null ? mat_price.PType : null,
                    Discount     = disc_card != null ? disc_card.OnValue : (discount ?? 0.00m),
                    Nds          = wb.Nds,
                    CurrId       = wb.CurrId,
                    OnValue      = wb.OnValue,
                    BasePrice    = price + Math.Round(price * wb.Nds.Value / 100, 2),
                    PosKind      = 0,
                    PosParent    = 0,
                    DiscountKind = disc_card != null ? 2 : 0,
                };
                _db.WaybillDet.Add(wbd);
            }
            else
            {
                mat.Amount += 1;
            }


            _db.SaveChanges();



            RefreshDet();
            WaybillDetOutGridView.MoveLast();
        }
Example #4
0
        private void frmWBReturnDetIn_Load(object sender, EventArgs e)
        {
            _wbd = _db.WaybillDet.Find(_PosId);

            if (_wbd == null)
            {
                _wbd = new WaybillDet()
                {
                    WbillId = _wb.WbillId,
                    Amount  = 0,
                    Num     = _wb.WaybillDet.Count() + 1,
                };
            }
            else
            {
                _temp_return_rel = _db.ReturnRel.FirstOrDefault(w => w.PosId == _wbd.PosId);
                if (_temp_return_rel != null)
                {
                    _db.ReturnRel.Remove(_temp_return_rel);
                    _db.SaveChanges();

                    ordered_in_list = _db.GetShippedPosIn(_temp_return_rel.OutPosId).ToList();
                }
            }

            WaybillDetBS.DataSource = _wbd;

            if (pos_out_list == null)
            {
                pos_out_list = _db.GetPosOut(_start_date, _wb.OnDate, 0, _wb.KaId, -1);
            }

            MatComboBox.Properties.DataSource = pos_out_list;
            if (_temp_return_rel != null)
            {
                MatComboBox.EditValue = _temp_return_rel.OutPosId;
            }

            if (outPosId != null)
            {
                MatComboBox.EditValue = outPosId.Value;
            }

            GetOk();
        }
Example #5
0
        private void frmWBInventoryDet_Load(object sender, EventArgs e)
        {
            _wbd = _db.WaybillDet.Find(_PosId);

            if (_wbd == null)
            {
                _wbd = new WaybillDet()
                {
                    WbillId = _wb.WbillId,
                    Amount  = 0,
                    Num     = _wb.WaybillDet.Count() + 1,
                    OnDate  = _wb.OnDate,
                    CurrId  = _wb.CurrId,
                    OnValue = 1,
                    WId     = _wb.WaybillMove.SourceWid
                };
            }

            WaybillDetBS.DataSource = _wbd;

            MatComboBox.Properties.DataSource = _db.WhMatGet(0, _wbd.WId, 0, DBHelper.ServerDateTime(), 0, "*", 0, "", DBHelper.CurrentUser.UserId, 0).ToList();

            GetOk();
        }
Example #6
0
        private void frmWBMoveDet_Load(object sender, EventArgs e)
        {
            WHComboBox.Properties.DataSource = DBHelper.WhList;
            var w_mat_turn = new List <WMatTurn>();


            if (_PosId == null)
            {
                _wbd = new WaybillDet()
                {
                    WbillId  = _wb.WbillId,
                    Amount   = 0,
                    OnValue  = _wb.OnValue,
                    WId      = _wb.WaybillMove != null ? (int?)_wb.WaybillMove.SourceWid : null,
                    Discount = 0,
                    Nds      = _wb.Nds,
                    Num      = _wb.WaybillDet.Count() + 1
                };
            }
            else
            {
                _wbd = _db.WaybillDet.Find(_PosId);

                w_mat_turn = _db.WMatTurn.Where(w => w.SourceId == _wbd.PosId).ToList();
                if (w_mat_turn.Count > 0)
                {
                    _db.WMatTurn.RemoveRange(w_mat_turn);
                    _db.SaveChanges();
                }
            }

            _materials_on_wh = GetMaterialsOnWh();

            int wh_id = _wb.WaybillMove != null ? _wb.WaybillMove.SourceWid : 0;

            MatComboBox.Properties.DataSource = _materials_on_wh.Where(w => w.WId == wh_id && w.Remain > 0).GroupBy(g => new { g.MatId, g.Name, g.MsrName }).Select(s => new WhMatGet_Result
            {
                MatId     = s.Key.MatId,
                MatName   = s.Key.Name,
                MsrName   = s.Key.MsrName,
                CurRemain = s.Sum(r => r.Remain) - s.Sum(r => r.Rsv),
                Rsv       = s.Sum(r => r.Rsv),
                Remain    = s.Sum(r => r.Remain)
            }).ToList(); // _db.WhMatGet(0, wh_id, _ka_id, DBHelper.ServerDateTime(), 0, "*", 0, "", DBHelper.CurrentUser.UserId, 0).ToList();


            if (_wbd != null)
            {
                WaybillDetBS.DataSource = _wbd;

                if (_db.Entry <WaybillDet>(_wbd).State == EntityState.Unchanged)
                {
                    GetContent();

                    GetPos();
                    foreach (var item in w_mat_turn)
                    {
                        if (pos_in.Any(a => a.PosId == item.PosId))
                        {
                            pos_in.FirstOrDefault(a => a.PosId == item.PosId).Amount = item.Amount;
                        }
                    }

                    if (w_mat_turn.Count == 0)
                    {
                        SetAmount();
                    }
                }
            }

            GetOk();
        }
Example #7
0
        private void frmWayBillDetOut_Load(object sender, EventArgs e)
        {
            if (_PosId == null)
            {
                _wbd = new WaybillDet()
                {
                    WbillId            = _wb.WbillId,
                    Amount             = 0,
                    Discount           = _cart != null ? _cart.OnValue : 0,
                    Nds                = _wb.Nds,
                    CurrId             = _wb.CurrId,
                    OnDate             = _wb.OnDate,
                    Num                = _db.GetWayBillDetOut(_wb.WbillId).Count() + 1,
                    OnValue            = _wb.OnValue,
                    PosKind            = 0,
                    PosParent          = 0,
                    DiscountKind       = _cart != null ? 2 : 0,
                    PtypeId            = _db.Kagent.Find(_wb.KaId).PTypeId,
                    WayBillDetAddProps = new WayBillDetAddProps {
                        CardId = _cart != null ? (int?)_cart.CardId : null
                    }
                };

                modified_dataset = false;
            }
            else
            {
                _wbd = _db.WaybillDet.Find(_PosId);

                modified_dataset = (_wbd != null);
            }

            if (_wbd != null)
            {
                WaybillDetBS.DataSource = _wbd;

                if (modified_dataset)
                {
                    var w_mat_turn = _db.WMatTurn.AsNoTracking().Where(w => w.SourceId == _wbd.PosId).ToList();
                    if (w_mat_turn.Count > 0)
                    {
                        //   _db.WMatTurn.RemoveRange(w_mat_turn);
                        //    _db.SaveChanges();
                        _db.DeleteWhere <WMatTurn>(w => w.SourceId == _wbd.PosId);

                        GetContent(_wbd.WId, _wbd.MatId);

                        foreach (var item in w_mat_turn)
                        {
                            var pos = pos_in.FirstOrDefault(a => a.PosId == item.PosId);
                            if (pos != null)
                            {
                                pos.Amount = item.Amount;

                                if (item.Amount == pos.FullRemain)
                                {
                                    pos.GetAll = 1;
                                }
                            }
                        }
                    }
                }

                if (_wbd.WayBillDetAddProps != null)
                {
                    WayBillDetAddPropsBS.DataSource = _wbd.WayBillDetAddProps;

                    if (_wbd.WayBillDetAddProps.CardId != null)
                    {
                        var disc_card = _db.DiscCards.Find(_wbd.WayBillDetAddProps.CardId);
                        DiscNumEdit.Text = disc_card.Num;
                        if (disc_card.Kagent != null)
                        {
                            textEdit6.Text = disc_card.Kagent.Name;
                        }
                    }
                }

                GetOk();
            }
        }
Example #8
0
        private void frmWriteOffDet_Load(object sender, EventArgs e)
        {
            WHComboBox.Properties.DataSource  = DBHelper.WhList;
            MatComboBox.Properties.DataSource = _db.MaterialsList.AsNoTracking().ToList();

            if (_wb.WType == -5 || _wb.WType == -22)
            {
                WHComboBox.Enabled = false;
            }
            if (_wb.WType == -22)
            {
                MatComboBox.Enabled = false;
            }

            if (_PosId == null)
            {
                _wbd = new WaybillDet()
                {
                    WbillId = _wb.WbillId,
                    Num     = _wb.WaybillDet.Count() + 1,
                    Amount  = amount != null ? (decimal)amount : 0,
                    OnValue = _wb.OnValue,
                    WId     = _wb.WaybillMove != null ? _wb.WaybillMove.SourceWid : _wb.WayBillMake != null ? _wb.WayBillMake.SourceWId : DBHelper.WhList.FirstOrDefault(w => w.Def == 1).WId,
                    Nds     = _wb.Nds,
                    CurrId  = _wb.CurrId,
                    OnDate  = _wb.OnDate,
                    MatId   = mat_id != null ? (int)mat_id : 0
                };
            }
            else
            {
                _wbd = _db.WaybillDet.Find(_PosId);
            }

            if (_wbd != null)
            {
                PriceEdit.DataBindings.Add(new Binding("EditValue", _wbd, "Price", true, DataSourceUpdateMode.OnValidation));
                MatComboBox.DataBindings.Add(new Binding("EditValue", _wbd, "MatId"));
                WHComboBox.DataBindings.Add(new Binding("EditValue", _wbd, "WId", true, DataSourceUpdateMode.OnPropertyChanged));
                AmountEdit.DataBindings.Add(new Binding("EditValue", _wbd, "Amount"));

                if (_db.Entry <WaybillDet>(_wbd).State == EntityState.Unchanged)
                {
                    var w_mat_turn = _db.WMatTurn.AsNoTracking().Where(w => w.SourceId == _wbd.PosId).ToList();
                    if (w_mat_turn.Count > 0)
                    {
                        // _db.WMatTurn.RemoveRange(w_mat_turn);
                        //   _db.SaveChanges();

                        _db.DeleteWhere <WMatTurn>(w => w.SourceId == _wbd.PosId);

                        GetContent();

                        foreach (var item in w_mat_turn)
                        {
                            if (pos_in.Any(a => a.PosId == item.PosId))
                            {
                                pos_in.FirstOrDefault(a => a.PosId == item.PosId).Amount = item.Amount;
                            }
                        }
                    }
                }
            }

            GetContent();
            GetOk();
        }
Example #9
0
        private void frmWayBillDetIn_Load(object sender, EventArgs e)
        {
            panel3.Visible = barCheckItem1.Checked;
            if (!barCheckItem1.Checked)
            {
                Height -= panel3.Height;
            }

            panel4.Visible = barCheckItem2.Checked;
            if (!barCheckItem2.Checked)
            {
                Height -= panel4.Height;
            }

            panel5.Visible = barCheckItem3.Checked;
            if (!barCheckItem3.Checked)
            {
                Height -= panel5.Height;
            }

            if (DBHelper.CurrentUser.ShowPrice == 0)
            {
                if (barCheckItem2.Checked)
                {
                    barCheckItem2.PerformClick();
                }
                barCheckItem2.Visibility = BarItemVisibility.Never;
            }

            if (_PosId == null)
            {
                _wbd = new WaybillDet()
                {
                    WbillId      = _wb.WbillId,
                    OnDate       = _wb.OnDate,
                    Discount     = 0,
                    Nds          = _wb.Nds,
                    CurrId       = _wb.CurrId,
                    OnValue      = _wb.OnValue,
                    Num          = _wb.WaybillDet.Count() + 1,
                    PosKind      = 0,
                    PosParent    = 0,
                    DiscountKind = 0,
                    Amount       = 1
                };

                modified_dataset = false;
            }
            else
            {
                _wbd             = _db.WaybillDet.Find(_PosId);
                modified_dataset = (_wbd != null);
            }

            if (_wbd != null)
            {
                var wid = _wbd.WId;
                WaybillDetBS.DataSource = _wbd;
                WHComboBox.EditValue    = wid;

                wbdp = _db.WayBillDetAddProps.FirstOrDefault(w => w.PosId == _wbd.PosId);
                if (wbdp == null)
                {
                    wbdp = new WayBillDetAddProps();
                }

                WayBillDetAddPropsBS.DataSource = wbdp;

                serials = _db.Serials.FirstOrDefault(w => w.PosId == _wbd.PosId);
                if (serials == null)
                {
                    serials = new Serials();
                }

                SerialsBS.DataSource = serials;

                MatComboBox.Enabled = (wbdp == null || wbdp.WbMaked == null);
                MatEditBtn.Enabled  = MatComboBox.Enabled;
                //   AmountEdit.Enabled = (MatComboBox.Enabled  );
                ManufEditBtn.Visible = ((wbdp == null || wbdp.WaybillList == null || wbdp.WaybillList.WType == -20) && _wb.WType == 5);

                CurrencyBS.DataSource = _db.Currency.Where(w => w.CurrId == _wb.CurrId).FirstOrDefault();
            }
            else
            {
                AmountEdit.EditValue = 1;
                PriceEdit.EditValue  = 0;
                ManufEditBtn.Visible = (_wb.WType == 5);
            }

            GetOk();

            groupControl1.Text = $"{groupControl1.Text}, {DBHelper.NationalCurrency.ShortName}";
        }