123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881 |
- var Unibase;
- (function (Unibase) {
- let Forms;
- (function (Forms) {
- let Controls;
- (function (Controls) {
- class ItemDetails extends Unibase.Platform.Core.BaseComponent {
- constructor() {
- super(...arguments);
- this.rowIndex = 0;
- this.deletedItems = new Array();
- this.itemIds = new Array();
- this.SplitedInvoiceItemList = new Array();
- this.deleted_invoiceItems = new Array();
- this.container = "";
- }
- init(formpropertyid, prop, callback) {
- var instance = ItemDetails.Instance();
- instance.loadControlSettings(prop.ControlJsonText, prop.FormPropertyId);
- instance.loadPropertySettings(prop.PropertySettings, prop.FormPropertyId);
- Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("platform/controls/itemdetails/item.mrp.js", function () {
- });
- }
- loadControl(containerid, prop) {
- var html = '<div class="section_ItemDetails card"><div class="card-header">Item Details</div><div class="card-body"><div class="row"><div id="control-container-100691780039438" class="control-group divCustomProperties divCustomProperties_InvoiceItemEntity controldata_0 col-sm-12 " data-size="12" data-propertyname="null" data-propertyid="0" data-doctypeid="0" data-level="0" data-doctypetable="null" data-doctypename="InvoiceItemEntity" data-isdefault="false" data-rowindex="13" data-formpropertyid="100691780039438" data-controlname="InvoiceItems" data-validatename="InvoiceItems"><div class="panel panel-default" style="padding-bottom:10px" id="invoiceitem"><input type="hidden" id="hdninvoiceitem" class="" value="" data-isdynamic="true" data-propdoctypename=""><div class="" style="padding-bottom:10px"> <div id="tbl_InvoiceItems" class="col-sm-12 d-none d-md-block "><div class="row lineheight wrapper-sm" style="border-bottom: 2px solid grey;"><div class="col-sm-4 min-padding"><strong class="ml-10">Item Name</strong></div><div class="col-sm-2 text-center"><strong class="">Qty</strong></div><div class="col-sm-2 text-center min-padding"><strong>Unit Price</strong></div><div class="col-sm-2 text-center min-padding"><strong>Disc.</strong></div><div class="col-sm-2 text-right min-padding"><strong>Total</strong></div></div></div></div><div class="panel-body InvoiceItems"><div class="item-row added-row InvoiceitemRow-0 "></div><div class="discount-row hidden"></div></div></div><a href="javascript:;" class="default pull-left" title="Add Item" data-original-title="Add Item"><span class="pull-right btn" style="text-decoration:underline;color:deepskyblue" id="btnInvoiceItem"> Add Item</span></a></div></div></div></div>';
- $("#" + containerid).html(html);
- $("#btnInvoiceItem").off().click(function () {
- ItemDetails.instance.AddRow();
- });
- ItemDetails.instance.container = containerid;
- Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("tenants/themes/default/components/details/details.js", function () {
- });
- }
- loadControlSettings(controlsettingjson, formpropertyid) {
- return null;
- }
- loadPropertySettings(propertysettings, formpropertyid) {
- return null;
- }
- bindEditFormDetails(formpropertyid, propval, DocPropertyName) {
- return null;
- }
- AddRow() {
- var emptyRow = {
- orderItemId: 0,
- invoiceItemId: 0,
- itemName: "",
- itemId: 0,
- itemSKU: "",
- unitName: "",
- packSize: 0,
- packCount: 0,
- packs: 0,
- quantity: 0,
- availPacks: 0,
- availQty: 0,
- listPrice: 0,
- description: "",
- taxGroupName: "",
- taxGroupId: 0,
- isTaxInclusive: $("#hfIsTaxInclusive").val(),
- addlDiscountPercent: 0,
- addlDiscountValue: 0,
- creditNote: 0,
- priceListId: 0,
- batchId: 0,
- unitPrice: 0,
- invoiceallocations: null,
- exciseInvoiceItem: null,
- accountId: 0,
- accountName: "",
- walletId: 0,
- Adjustment: 0,
- IsFoc: false,
- TariffNo: "",
- exciseAmount: 0,
- discountName: "",
- discountId: 0,
- _description: "",
- refNo: "",
- DiscountGroupId: 0,
- DiscountGroupName: '',
- RefInvoiceItemId: 0,
- MrpId: 0,
- taxAdjustment: 0,
- assesableAdjustment: 0,
- inventoryTypeId: 0,
- dcItemId: 0,
- TotalRowAmount: 0,
- maxQty: 0,
- };
- this.addDataRow(emptyRow);
- }
- addDataRow(row) {
- Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("tenants/themes/default/components/details/details.js", function () {
- });
- this.rowIndex = $(".InvoiceItems").find(".item-addedrow").length + 1;
- var bg = "";
- if (row.packSize == 0)
- row.packSize = 1;
- if (row.packCount == 0)
- row.packCount = 1;
- if (row.quantity == 0)
- row.quantity = row.packCount * row.packs * row.packSize;
- var price = row.unitPrice;
- if (row.unitPrice == 0)
- price = row.listPrice;
- var currenttaxgroupid = 0;
- if ($("#hfInv_Invoicetype").val() == "PurchaseReturn" || $("#hfInv_Invoicetype").val() == "SalesReturn")
- row.invoiceallocations = null;
- if ($('#hfInv_IsRetun').val() == 1)
- row.invoiceItemId = 0;
- var zeroBilled = "";
- if (price == 0)
- zeroBilled = "bg-danger";
- var zeroQtyText = "";
- var zeroQtyDiv = "bg-light";
- var recordId = Unibase.Themes.Providers.Detail_Settings.Instance().RecordId;
- if (recordId == 0 || recordId == undefined) {
- if ($('#hfInv_IsRetun').val() == 1 && row.itemId != 0 && ($('#hfInv_Invoicetype').val() == 'Sales' || $('#hfInv_Invoicetype').val() == 'PurchaseReturn')) {
- if (row.availQty == 0) {
- row.quantity = 0;
- zeroQtyText = "text-danger";
- zeroQtyDiv = "bg-danger";
- }
- else if (row.availQty < row.quantity) {
- row.quantity = row.availQty;
- }
- }
- }
- var readonlyQty = "";
- if (($("#hfDcId").val() != "0" || $("#hfDcId").val() == "") && recordId == 0) {
- readonlyQty = "readonly";
- }
- var ManageInvoice = 2;
- var AutoDc = false;
- var ManageInvoiceTax = 2;
- var readonlyPrice = "";
- var readonlyDisc = "";
- var readonlyTax = "";
- if (ManageInvoice == 1 && AutoDc == false) {
- readonlyQty = "readonly";
- readonlyPrice = "readonly";
- readonlyDisc = "readonly";
- readonlyTax = "disabled";
- }
- if ($('#hfInv_Invoicetype').val() == "Sales" && ManageInvoiceTax == 1 && AutoDc == false) {
- readonlyTax = "readonly";
- }
- if (row.inventoryTypeId == "2") {
- readonlyQty = "";
- readonlyPrice = "";
- }
- var activeDiscVal = "";
- var activeDiscPercent = "";
- var activeDiscMul = "";
- var activeDiscText = "";
- var discValue = 0;
- if (row.addlDiscountPercent > 0) {
- discValue = row.addlDiscountPercent;
- activeDiscPercent = "active";
- activeDiscText = "%";
- }
- else if (row.addlDiscountValue > 0 && row.DiscountGroupId > 0) {
- discValue = row.addlDiscountValue;
- activeDiscMul = "active";
- activeDiscText = "Mul";
- }
- else {
- discValue = row.addlDiscountValue;
- activeDiscVal = "active";
- activeDiscText = "Val";
- }
- var itemNameClass = "floating-label-form-group";
- if (row.invoiceItemId != 0)
- itemNameClass = "";
- var mt = "";
- if (row.invoiceItemId != 0) {
- mt = "mt-5";
- }
- if (row.orderItemId != 0) {
- mt = "mt-10";
- }
- if (row.inventoryTypeId != 5 && row.inventoryTypeId != 6 && row.inventoryTypeId != 7) {
- var IsBom = "";
- if (row.IsBoMItem == true && row.IsBoMItem != undefined) {
- IsBom = "hidden";
- }
- var html = '<div id="div_itemAddedRow_' + this.rowIndex + '" class="item-row item-addedrow ' + bg + ' form-group">' +
- '<div class="row ' + IsBom + ' divItemRow_' + row.itemId + ' ">' +
- '<div class="col-sm-4">' +
- '<div class=" item-name min-padding" style="margin-left:20px;">' +
- '<lable for="lbl_itemname" class="d-md-none">Item Name</lable>' +
- '<input type="hidden" class="rowIndex" value="' + this.rowIndex + '" />' +
- '<input type="hidden" class="orderItemId" value="' + row.orderItemId + '" />' +
- '<input type="hidden" class="dcItemId" value="' + row.dcItemId + '" />' +
- '<input type="hidden" class="selectedInvoiceItemId" value="' + row.invoiceItemId + '" />' +
- '<input type="hidden" class="refInvoiceItemId" value="' + row.RefInvoiceItemId + '" />' +
- '<input type="hidden" class="selectedItemId" id="hf_txtitem_' + this.rowIndex + '" value="' + row.itemId + '" />' +
- '<input type="hidden" id="selectedItemId" value="' + row.itemId + '" />' +
- '<input type="hidden" class="hfMrpId" value="' + row.MrpId + '" />' +
- '<input type="hidden" class="offerapplied" value="0" />' +
- '<input type="hidden" class="refNo" value="' + row.refNo + '"/>' +
- '<input type="hidden" class="description" value="' + row.description + '"/>' +
- '<input type="hidden" class="IsExchangeItem" value="' + row.ExchangeItem + '" />' +
- '<input type="hidden" class="maxQty" value="' + row.maxQty + '" />' +
- '<input type="hidden" class="hfAccountId" value="' + row.accountId + '"/>' +
- '<input type="hidden" class="hfItemTaxAdjsutmentVal" value="' + row.taxAdjustment + '" />' +
- '<input type="hidden" class="hfItemAssesableAdjustmentVal" value="' + row.assesableAdjustment + '" />' +
- '<input type="hidden" class="hfoldItemId" value="' + row.itemId + '"/>' +
- '<input type="hidden" class="hf_IsFoc" value="' + row.IsFoc + '"/>';
- if (row.IsFoc == true) {
- html += '<input type="hidden" class="hfOfferedItemId" value="' + row.OfferItemId + '"/>';
- }
- html += '<div class="' + mt + '">' +
- '<a class="no-border bg-white delete" href = "javascript:;" title = "Remove row" style = "" > <i class="fa fa-trash-o fa-lg mt-15 mr-2" style="margin-left:-25px;color:red"></i></a>';
- if (row.invoiceItemId != 0) {
- var itemName = row.itemSKU + ' - ' + row.itemName;
- if (row.ExchangeItem)
- itemName = '(Exchange) ' + row.itemSKU + ' - ' + row.itemName;
- html += '<a class="default prodName-link mt-10 ItemName" href="javascript:;">' + itemName + '</a>';
- }
- else {
- var itemName = "";
- if (row.ExchangeItem)
- itemName = '(Exchange) ' + row.itemName;
- else if (itemName != "" && row.itemSKU != "") {
- itemName = row.itemSKU + '-' + row.itemName;
- html += '<a class="default prodName-link mt-10 ItemName" href="javascript:;">' + itemName + '</a>';
- }
- else if (itemName != "") {
- itemName = row.itemName;
- html += '<a class="default prodName-link mt-10 ItemName" href="javascript:;">' + itemName + '</a>';
- }
- else {
- html += '<select class="form-control prodName" value="" id="txt_item_' + this.rowIndex + '" placeholder=" Select the item to Invoice" style="width:100%;" id="txtItem"></select>';
- }
- }
- html += '</div>' +
- '</div></div>' +
- '<div class="col-sm-2 input-group pr-0">' +
- '<div class="col-sm-1 pl-0"><a class="btn btn-sm btn_offer hidden"><span class="badge badge-sm bg-danger count mt-20" style="color:white;margin-left:-30px">offer</span></a></div>' +
- '<div class="col-sm-10 pl-0">' +
- '<div class="floating-label-form-group text-center">' +
- '<lable for="lbl_qty" class="d-md-none">Qty</lable>' +
- '<input type="text" class="prodQuantity text-center ' + zeroQtyText + ' form-control" placeholder="0.00" value="' + row.quantity + '" ' + readonlyQty + ' />' +
- '</div>' +
- '</div>' +
- '</div>' +
- '<div class="col-sm-2 div_UnitPrice">' +
- '<div class="floating-label-form-group min-padding text-center"><lable for="lbl_unitprice" class="d-md-none">Unit Price</lable>';
- var readonly = "";
- html += '<input type="text" class="prodPrice text-center form-control" placeholder="0.00" value="' + price + '" ' + readonlyPrice + ' />';
- html += '</div></div>' +
- '<div class="col-sm-2 div_SplitInvoiceItem hidden"><div class="mt-20 text-center"><a href="javascript:;" class="mr-10"><span id="spn_InvoiceItem_' + this.rowIndex + '" class="spn_InvoiceItem" style="text-decoration:underline;">Select</span></a></div></div>' +
- '<div class="col-sm-2 div_Discount"> ' +
- '<div class="floating-label-form-group text-center">' +
- '<lable for="lbl_disc" class="d-md-none">Disc.</lable>' +
- '<input type="hidden" id="hfProdDiscountGroupId" value="' + row.DiscountGroupId + '" />' +
- '<input type="hidden" id="hfProdDiscountGroupName" value="' + row.DiscountGroupName + '" />' +
- '<input type="hidden" id="hfProdDiscountList" value="" />' +
- '<input type="hidden" id="hfProdDiscountApplyTypes" value="" />' +
- '<div class="input-group">' +
- '<input type="text" id="inv_txtdiscount" placeholder="0.00" class="form-control inv_txtaddldiscount" value="' + discValue + '" ' + readonlyDisc + '>' +
- '<div class="input-group-btn">' +
- '<select class="btnInvoice_DiscType btn_inv_DiscType mt-10 border-blue"><option value="Val">Val</option><option value="%">%</option></select>' +
- '</div>' +
- '</div>' +
- '</div>' +
- '</div>' +
- '<div class="col-sm-2">' +
- '<input type="hidden" class="hfDiscountedAmount" value="0" />' +
- '<input type="hidden" class="hfRowTotalAdjustment" value="' + row.Adjustment + '" />' +
- '<input type="hidden" class="hfAssesableAdjustment" value="" />' +
- '<input type="hidden" class="hfTaxAdjustment" value="" />';
- if ($("#hfInv_Invoicetype").val() == "Purchase" || $("#hfInv_Invoicetype").val() == "PurchaseReturn" || $("#hfInv_Invoicetype").val() == "DebitNote") {
- html += '<a href="javascript:;" class=Adjustmentrow><input type="text" class="hfRowTotalwithAdjustment form-control txtRowTotalwithAdjustment text-right" value="0" style="color:#5ba8fb;cursor:pointer" disabled/></a>';
- html += '<a href="javascript:;" class="hidden" onclick="javascript:_bizgazetransact_invoice_edit.editInvItemTaxAllocs(' + row.invoiceItemId + ',' + row.taxGroupId + ',' + row.itemId + ',' + row.orderItemId + ')"><input type="text" style="color:#5ba8fb;text-decoration:underline;cursor:pointer" class="hfRowTotal form-control txtRowTotal text-right" value="0" /></a>';
- }
- else {
- html += '<p class="pull-right mt-10 mr-15 text-center"><lable for="lbl_disc" class="d-md-none">Total:</lable><strong><input type="hidden" class="hfRowTotal" value="0" /><span class="prodTotalPrice">0.00</span></strong></p>';
- }
- html += '</div>' +
- '</div><div class="hidden div_MoreDetails clear mt-5 ' + zeroQtyDiv + '">' +
- '<div class="row ml-5 mr-5">' +
- '<div class="col-sm-3">' +
- '<div class="floating-label-form-group form-group floating-label focus">' +
- '<label for="from_lbl_Description" id="lbl_Description">Description</label>' +
- '<input type="text" id="txt_Description" data-isdynamic="false" class="form-control floating-label-control " data-placeholder="Enter Description" placeholder="Description" data-label="Description"/>' +
- '</div>' +
- '</div>' +
- '<div class="col-sm-3">' +
- '<div class="floating-label-form-group-with-value">' +
- '<label for="from_lbl_Output" id="lbl_Output">Tax Group<span class="text-danger">*</span></label>' +
- '<div class="input-group">';
- if (row.taxGroupId != 0) {
- html += '<select type="text" data-isdynamic="false" class="form-control ui-autocomplete prodTax required ' + readonlyTax + '" value="' + row.taxGroupName + '" data-placeholder="Output @ 18%" placeholder="Output" data-label="Output" style="width:100%;" data-required="true"></select>' +
- '<input type="hidden" id="hfProdTaxPercent_' + this.rowIndex + '" class="hfProdTaxPercent" value="0" />' +
- '<input type="hidden" id="hfProdTax_' + this.rowIndex + '" class="hfProdTax hidden" value="' + row.taxGroupId + '"/>' +
- '<input type="hidden" class="txtProdTax hidden" value="' + row.taxGroupName + '"/>';
- }
- else {
- html += '<select type="text" data-isdynamic="false" class="form-control text-control required select2-hidden-accessible prodTax required ' + readonlyTax + '" id="txt_prodTax_' + this.rowIndex + '" data-placeholder="Output @ 18%" placeholder="Output" data-label="Output" style="width:100%;" data-required="true" id="prodTax"></select>' +
- '<input type="hidden" id="hfProdTaxPercent_' + this.rowIndex + '" class="hfProdTaxPercent" value="0" />' +
- '<input type="hidden" id="hfProdTax_' + this.rowIndex + '" class="hfProdTax hidden" value="0"/>' +
- '<input type="hidden" class="txtProdTax hidden" value=""/>';
- }
- html += '</div>' +
- '</div>' +
- '</div>' +
- '<div class="col-sm-3">' +
- '<div class="floating-label-form-group-with-value">' +
- '<label for="from_lbl_Account" id="lbl_Account">Account<span class="text-danger">*</span></label>';
- if (row.accountId != 0) {
- html += '<select data-isdynamic="false" class="form-control txt_Account required ' + readonlyTax + '" data-placeholder="Account Number" placeholder="Account" data-label="Account" value="' + row.accountName + '" id="txt_Account_' + this.rowIndex + '" style="width:100%;" data-required="true"></select>' +
- '<input type="hidden" id="hf_Account_' + this.rowIndex + '" class="hf_Account" value="' + row.accountId + '" />' +
- '<input type="hidden" id="txt_AccountName_' + this.rowIndex + '" class="txt_AccountName" value="' + row.accountName + '"/>';
- }
- else {
- html += '<select data-isdynamic="false" class="form-control text-control required select2-hidden-accessible txt_Account required ' + readonlyTax + '" data-placeholder="Account Number" placeholder="Account" id="txt_Account_' + this.rowIndex + '" data-label="Account" style="width:100%;" data-required="true"></select>' +
- '<input type="hidden" id="hf_Account_' + this.rowIndex + '" class="hf_Account" value="0" />' +
- '<input type="hidden" id="txt_AccountName_' + this.rowIndex + '" class="txt_AccountName" value=""/>';
- }
- html += '</div>' +
- '</div>' +
- '<div class="col-sm-3 mt-40 text-right">' +
- '<label for="from_lbl_Avalilability" id="lbl_Avalilability"><b>Availability:   </b></label>' +
- '<span class=" prodAvail">' + row.availQty + '</span>' +
- '</div>' +
- '</div>' +
- '<div class="row">' +
- '<div class="col-sm-12">' +
- '<div class="col-sm-3 form-group div_Mrp hidden">' +
- '<div class="floating-label-form-group floating-label focus">' +
- '<input type="hidden" class="hf_PriceList" value="' + row.priceListId + '" />' +
- '<label for="from_lbl_MRP" id="lbl_MRP">MRP</label>' +
- '<input type="text" data-isdynamic="false" class="form-control floating-label-control txt_MRP" data-placeholder="53" placeholder="MRP" data-label="MRP" />' +
- '</div>' +
- '</div>' +
- '</div>' +
- '<div class="orderitemlist"></div>' +
- '</div><div class="accountRow"></div>';
- $(".item-row:last").after(html);
- var element = $(".item-addedrow:last");
- $("#spn_InvoiceItem_" + this.rowIndex).click(function () {
- ItemDetails.Instance().loadMrp(element);
- });
- ItemDetails.instance.itemsAutoComplete(element);
- $('.inv_txtaddldiscount').keypress(function (event) {
- if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
- }
- else {
- event.preventDefault();
- }
- }).on('paste', function (event) {
- event.preventDefault();
- });
- $('.prodQuantity').keypress(function (event) {
- if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
- }
- else {
- event.preventDefault();
- }
- }).on('paste', function (event) {
- event.preventDefault();
- });
- $('.prodPrice').keypress(function (event) {
- if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
- }
- else {
- event.preventDefault();
- }
- }).on('paste', function (event) {
- event.preventDefault();
- });
- ItemDetails.Instance().RemoveItem(element);
- element.find(".btnInvoice_DiscType option[value='" + activeDiscText + "']").prop("selected", true);
- element.find(".prodPrice,.prodQuantity,.inv_txtaddldiscount").focusin(function () {
- if (element.find($(".prodName")).val() != null || element.find($(".ItemName")).val() != null) {
- $(".div_MoreDetails").addClass("hidden");
- element.find(".div_MoreDetails").removeClass("hidden");
- }
- });
- element.find(".prodName").focusin(function () {
- $(".divMoreDetails").addClass("hidden");
- });
- if (row.description != null && row.description != '' && row.description != 'null')
- element.find('#txt_Description').val(row.description);
- element.find("#inv_txtdiscount").change(function () {
- if (!element.hasClass('SplitItem')) {
- if (element.find(".btnInvoice_DiscType").val() == "%") {
- if (Number(element.find("#inv_txtdiscount").val()) > 100) {
- element.find("#inv_txtdiscount").val("100");
- }
- }
- }
- });
- if (!element.hasClass('SplitItem')) {
- }
- if (row.TotalRowAmount != 0) {
- if ($("#hfInv_Invoicetype").val() == "Purchase" || $("#hfInv_Invoicetype").val() == "PurchaseReturn" || $("#hfInv_Invoicetype").val() == "DebitNote") {
- element.find(".hfRowTotalwithAdjustment").val();
- }
- else {
- element.find('.prodTotalPrice').text('');
- }
- }
- if (row.TotalDiscount != 0 && row.TotalDiscount != undefined)
- if (row.invoiceItemId != "0" && ($("#hfInv_Invoicetype").val() == "Purchase" || $("#hfInv_Invoicetype").val() == "SalesReturn" || $("#hfInv_Invoicetype").val() == "DebitNote")) {
- var x = element.find('.hfRowTotalwithAdjustment');
- element.find('.AdjustmentRow').click(function () {
- });
- }
- if (row.IsFoc == true) {
- element.find('.delete').addClass('hidden');
- element.find('.prodQuantity').prop('readonly', 'readonly');
- element.find('.prodPrice').prop('readonly', 'readonly');
- element.find("#inv_txtdiscount").prop('readonly', 'readonly');
- element.find(".btnInvoice_DiscType").prop('disabled', true);
- element.find('.prodQuantity').css('cursor', 'not-allowed');
- element.find('.prodPrice').css('cursor', 'not-allowed');
- element.find("#inv_txtdiscount").css('cursor', 'not-allowed');
- }
- }
- else {
- var element = $(".discount-addedrow:last");
- if (row.inventoryTypeId == 7) {
- element = $(".netdiscount-addedrow:last");
- }
- else {
- }
- }
- }
- loadMrp(element) {
- var instance = this;
- Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("platform/controls/itemdetails/item.mrp.js", function () {
- instance.navigationHelper.popup(0, "", Unibase.Forms.Controls.MRPDetails.Instance(), null, Unibase.Platform.Helpers.Size.Large);
- Controls.MRPDetails.element = element;
- Unibase.Forms.Controls.MRPDetails.Instance().init(element, "", 2);
- });
- }
- loadTaxGroupAutoComplete(element) {
- var txtTaxGroup = element.find(".prodTax");
- var hfProdTax = element.find(".hfProdTax");
- var hfAccount = element.find(".hf_Account");
- var txtAccount = element.find(".txt_Account");
- var accid = element.find(".hf_Account").val();
- var taxgrpid = element.find(".hfProdTax").val();
- var taxgrptext = element.find(".txtProdTax").val();
- var acctext = element.find(".txt_AccountName").val();
- var applytype = "Sales";
- var url = _appsettings.server_url() + '/apis/v4/unibase/platform/forms/getformsautocomplete';
- AutoCompleteHelper.getHelper().Create("#txt_prodTax_" + this.rowIndex, hfProdTax, url, function (response) {
- var data = response;
- });
- var url = _appsettings.server_url() + '/apis/v4/unibase/platform/forms/getformsautocomplete';
- AutoCompleteHelper.getHelper().Create("#txt_Account_" + this.rowIndex, hfAccount, url, function (response) {
- var data = response;
- });
- if (taxgrpid != 0) {
- $("#hf_TaxGroupId").val(taxgrpid);
- if ($("#ddl_TaxGroupId option[value='" + taxgrpid + "']").attr("selected", "selected").length == 0) {
- $("#ddl_TaxGroupId").append(new Option(taxgrptext, taxgrpid, true));
- }
- else {
- $("#ddl_TaxGroupId option[value='" + taxgrpid + "']").attr("selected", "selected");
- }
- }
- if (accid != 0) {
- $("#hf_AccountId").val(accid);
- if ($("#ddl_AccountId option[value='" + accid + "']").attr("selected", "selected").length == 0) {
- $("#ddl_AccountId").append(new Option(acctext, accid, true));
- }
- else {
- $("#ddl_AccountId option[value='" + accid + "']").attr("selected", "selected");
- }
- }
- }
- update_total() {
- var totalAmount = 0;
- var totalDiscountAmount = 0;
- var totalNonDiscountedAmount = 0;
- var totalTaxAmount = 0;
- var totalTaxAdjustment = 0;
- var totalAsseableAdjustment = 0;
- var totalQty = 0;
- var totalDiscountPercent = 0;
- var totalDiscountValue = 0;
- var totalAddlDiscountPercent = 0;
- var totalAddlDiscountValue = 0;
- var totalExpensePercent = 0;
- var totalExpenseValue = 0;
- var addexpenserow_total = 0;
- $('.expenserow-total').each(function (i) {
- var expense_row_total = Number($(this).html());
- addexpenserow_total += expense_row_total;
- });
- var ConsumedWalletValue = 0;
- var totalTaxPercent = 0;
- var totalTaxValue = 0;
- var totalCreditNote = 0;
- var adddiscountrow_total = 0;
- var netadddiscountrow_total = ConsumedWalletValue;
- $('.discount-row-total').each(function (i) {
- var discount_row_total = Number($(this).html());
- adddiscountrow_total += discount_row_total;
- });
- $('.netdiscount-row-total').each(function (i) {
- var discount_row_total = Number($(this).html());
- netadddiscountrow_total += discount_row_total;
- });
- var itemdiscount_total = 0;
- var totalLineAmount_total = 0;
- $('.hfRowTotal').each(function (i) {
- var element = $(this).parents(".item-row");
- if (!element.hasClass('SplitItem')) {
- var totalLineAmount = Number($(this).val());
- if (!isNaN(totalLineAmount))
- totalLineAmount_total += Number(totalLineAmount);
- var discountPercent = 0;
- var discountValue = 0;
- var quantity = Number(element.find(".prodQuantity").val());
- var unitPrice = Number(element.find(".prodPrice").val());
- var exciseAmount = Number(element.find(".exciseAmount").val());
- if (isNaN(exciseAmount))
- exciseAmount = 0;
- var nonexciseAmount = totalLineAmount - exciseAmount;
- if (element.find(".btnInvoice_DiscType option:selected").text().trim() == 'Val' && element.find('.inv_txtaddldiscount').val() != '' && element.find('.inv_txtaddldiscount').val() != undefined) {
- discountValue = Number(element.find('.inv_txtaddldiscount').val());
- }
- else if (element.find(".btnInvoice_DiscType option:selected").text().trim() == '%' && element.find('.inv_txtaddldiscount').val() != '' && element.find('.inv_txtaddldiscount').val() != undefined) {
- discountPercent = Number(element.find('.inv_txtaddldiscount').val());
- }
- else if (element.find(".btnInvoice_DiscType option:selected").text().trim() == 'Mul') {
- if (element.find('#hfProdDiscountList').val() != '' || element.find('#hfProdDiscountApplyTypes').val() != '') {
- var discountsArray = element.find('#hfProdDiscountList').val().toString().split(',');
- var applyTypes = element.find('#hfProdDiscountApplyTypes').val().toString().split(',');
- var price = Number(unitPrice) * Number(quantity);
- var currentAmount = Number(unitPrice) * Number(quantity);
- $.each(discountsArray, function (j) {
- var percent = discountsArray[j];
- var applyType = applyTypes[j];
- var discount = 0;
- if (applyType == 'NET' || applyType == '1') {
- discount = Number(price) * Number(percent) / 100;
- currentAmount -= Number(discount);
- }
- else {
- discount = Number(currentAmount) * Number(percent) / 100;
- currentAmount -= Number(discount);
- }
- discountValue += Number(discount);
- });
- element.find('.inv_txtaddldiscount').val(discountValue);
- }
- else {
- discountValue = Number(element.find('.inv_txtaddldiscount').val());
- }
- }
- if (!isNaN(discountPercent))
- totalDiscountPercent += Number(discountPercent);
- if (!isNaN(discountValue))
- totalAddlDiscountValue += Number(discountValue);
- var discountAmount = 0;
- discountAmount = (Number(nonexciseAmount) * Number(discountPercent) / 100)
- + (Number(quantity) * Number(discountValue));
- itemdiscount_total += discountAmount;
- var discountedAmount = Number(totalLineAmount) - Number(discountAmount);
- totalDiscountAmount += Number(discountAmount);
- element.find(".hfDiscountedAmount").val(discountAmount);
- if ($("#hfInv_Invoicetype").val() == "Purchase" || $("#hfInv_Invoicetype").val() == "PurchaseReturn" || $("#hfInv_Invoicetype").val() == "DebitNote") {
- element.find(".txtRowTotalwithAdjustment").val(totalLineAmount - discountAmount);
- }
- else
- element.find(".prodTotalPrice").html((totalLineAmount - discountAmount).toString());
- }
- });
- if (this.SplitedInvoiceItemList.length > 0) {
- for (var i = 0; i < this.SplitedInvoiceItemList.length; i++) {
- var totalline_Amount = Number(this.SplitedInvoiceItemList[i].quantity * this.SplitedInvoiceItemList[i].unitPrice);
- var discountAmount = 0;
- var nonexciseAmount = totalline_Amount - Number(this.SplitedInvoiceItemList[i].exciseAmount);
- discountAmount = (Number(nonexciseAmount) * Number(this.SplitedInvoiceItemList[i].addlDiscountPercent) / 100)
- + (Number(this.SplitedInvoiceItemList[i].quantity) * Number(this.SplitedInvoiceItemList[i].addlDiscountValue));
- discountAmount = Number(discountAmount);
- totalLineAmount_total += Number(this.SplitedInvoiceItemList[i].quantity * this.SplitedInvoiceItemList[i].unitPrice);
- itemdiscount_total += discountAmount;
- totalDiscountAmount += discountAmount;
- }
- }
- var overalldiscountpercent = 0;
- if (adddiscountrow_total != 0) {
- overalldiscountpercent = (100 * Number(adddiscountrow_total)) / Number(totalLineAmount_total);
- overalldiscountpercent = Number(overalldiscountpercent);
- $("#hfOverallDiscountPercent").val(overalldiscountpercent);
- }
- var taxAmounts = [];
- $('.hfRowTotal').each(function (i) {
- var element = $(this).parents(".item-row");
- if (!element.hasClass('SplitItem')) {
- var totalLineAmount = Number($(this).val());
- var quantity = element.find(".prodQuantity").val();
- if (!isNaN(totalLineAmount))
- totalNonDiscountedAmount += Number(totalLineAmount);
- discountAmount = Number(element.find(".hfDiscountedAmount").val()) + (Number(totalLineAmount) * Number(overalldiscountpercent) / 100);
- var assesableAmount = totalLineAmount - discountAmount;
- assesableAmount = Number(assesableAmount);
- var taxPercents = element.find(".hfProdTaxPercent").val();
- if (taxPercents != undefined)
- var taxpercentarray = taxPercents.toString().split(',');
- var taxValue = 0;
- var assesableAdjustment = Number(element.find('.hfItemAssesableAdjustmentVal').val());
- var taxAdjustment = Number(element.find('.hfItemTaxAdjsutmentVal').val());
- if (!isNaN(taxAdjustment))
- totalTaxAdjustment += Number(taxAdjustment);
- if (!isNaN(assesableAdjustment))
- totalAsseableAdjustment += Number(assesableAdjustment);
- var cumlTax = 0;
- var cumtaxtotal = 0;
- if ($("#hfId_IsTaxInclusive").val() == "true") {
- for (var i = 0; i < taxpercentarray.length; i++) {
- var taxPercentModel1 = taxpercentarray[i];
- var taxPercentM1 = Number(taxPercentModel1.split(":"));
- if (!isNaN(taxPercentM1[1]))
- cumlTax += Number(taxPercentM1[1]);
- }
- var currentAmt = Number((Number(assesableAmount) * 100) / (100 + Number(cumlTax)));
- cumtaxtotal = (Number(assesableAmount) - Number(currentAmt));
- }
- if (taxpercentarray != undefined) {
- for (var i = 0; i < taxpercentarray.length; i++) {
- var taxPercentModel = taxpercentarray[i];
- var taxPercentM = taxPercentModel.split(":");
- var ledgerid = taxPercentM[0];
- var taxPercent = Number(taxPercentM[1]);
- var taxAmt = 0;
- if ($("#hfId_IsTaxInclusive").val() == "true") {
- taxAmt = Number((taxPercent * cumtaxtotal) / cumlTax);
- }
- else {
- var tax = (Number(assesableAmount) * Number(taxPercent) / 100);
- taxAmt = Number(tax);
- }
- var ledgerexists = false;
- $.map(taxAmounts, function (e, i) {
- if (e.LedgerId == ledgerid) {
- ledgerexists = true;
- taxAmounts[i].TaxAmount += taxAmt;
- }
- });
- if (!ledgerexists) {
- taxAmounts.push({
- LedgerId: ledgerid,
- TaxAmount: taxAmt,
- });
- }
- }
- }
- totalAmount += Number(totalLineAmount);
- totalQty += Number(quantity);
- }
- });
- if (this.SplitedInvoiceItemList.length > 0) {
- for (var i = 0; i < this.SplitedInvoiceItemList.length; i++) {
- var TotalLineAmount = Number(this.SplitedInvoiceItemList[i].quantity * this.SplitedInvoiceItemList[i].unitPrice);
- var quantiy = Number(this.SplitedInvoiceItemList[i].quantity);
- if (!isNaN(TotalLineAmount))
- totalNonDiscountedAmount += Number(TotalLineAmount);
- var discountAmount = Number(this.SplitedInvoiceItemList[i].addlDiscountValue) + (Number(TotalLineAmount) * Number(this.SplitedInvoiceItemList[i].addlDiscountPercent) / 100);
- var assesableAmount = TotalLineAmount - discountAmount;
- assesableAmount = Number(assesableAmount);
- var taxPercents = '';
- var instance = this;
- if (this.SplitedInvoiceItemList[i].TaxPercent == undefined || this.SplitedInvoiceItemList[i].TaxPercent == 0) {
- var element = "";
- $(".SplitItem").each(function () {
- if ($(this).find(".selectedItemId").val() == instance.SplitedInvoiceItemList[i].itemId) {
- element = $(this);
- taxPercents = element.find('.hfProdTaxPercent').val();
- }
- });
- }
- else
- taxPercents = instance.SplitedInvoiceItemList[i].TaxPercent;
- if (taxPercents != undefined && taxPercents != '')
- var taxpercentarray = taxPercents.split(',');
- var assesableAdjustment = instance.SplitedInvoiceItemList[i].assesableAdjustment;
- var taxAdjustment = instance.SplitedInvoiceItemList[i].taxAdjustment;
- if (!isNaN(taxAdjustment))
- totalTaxAdjustment += Number(taxAdjustment);
- if (!isNaN(assesableAdjustment))
- totalAsseableAdjustment += Number(assesableAdjustment);
- var cumlTax = 0;
- var cumtaxtotal = 0;
- if ($("#hfId_IsTaxInclusive").val() == "true") {
- for (var j = 0; j < taxpercentarray.length; j++) {
- var taxPercentModel1 = taxpercentarray[j];
- var taxPercentM1 = taxPercentModel1.split(":");
- if (!isNaN(taxPercentM1[1]))
- cumlTax += Number(taxPercentM1[1]);
- }
- var currentAmt = Number((Number(assesableAmount) * 100) / (100 + Number(cumlTax)));
- cumtaxtotal = (Number(assesableAmount) - Number(currentAmt));
- }
- if (taxpercentarray != undefined) {
- for (var k = 0; k < taxpercentarray.length; k++) {
- var taxPercentModel = taxpercentarray[k];
- var taxPercentM = taxPercentModel.split(":");
- var ledgerid = taxPercentM[0];
- var taxPercent = taxPercentM[1];
- var taxAmt = 0;
- if ($("#hfId_IsTaxInclusive").val() == "true") {
- taxAmt = Number((taxPercent * cumtaxtotal) / cumlTax);
- }
- else {
- var tax = (Number(assesableAmount) * Number(taxPercent) / 100);
- taxAmt = Number(tax);
- }
- var ledgerexists = false;
- $.map(taxAmounts, function (e, m) {
- if (e.LedgerId == ledgerid) {
- ledgerexists = true;
- taxAmounts[m].TaxAmount += taxAmt;
- }
- });
- if (!ledgerexists) {
- taxAmounts.push({
- LedgerId: ledgerid,
- TaxAmount: taxAmt,
- });
- }
- }
- }
- totalAmount += Number(TotalLineAmount);
- totalQty += Number(quantiy);
- }
- }
- var taxAmount = 0;
- var taxAdjustment = 0;
- for (var i = 0; i < taxAmounts.length; i++) {
- if (!isNaN(taxAmounts[i].TaxAmount)) {
- taxAmount += Number(taxAmounts[i].TaxAmount);
- }
- }
- if (!isNaN(totalTaxAdjustment))
- totalTaxAdjustment = totalTaxAdjustment;
- if (!isNaN(totalAsseableAdjustment)) {
- totalAsseableAdjustment = totalAsseableAdjustment;
- }
- else {
- totalAsseableAdjustment = 0;
- }
- if (!isNaN(totalAsseableAdjustment))
- totalAmount += Number(totalAsseableAdjustment);
- totalTaxAmount = Number(taxAmount) + Number(totalTaxAdjustment);
- totalDiscountAmount += adddiscountrow_total;
- var totaltax = totalTaxAmount;
- var grosstotal = totalAmount;
- var creditnotes = 0;
- var assessableadjustment = 0;
- if (!isNaN(Number($("#txt_AssessableAdjustment").val())))
- assessableadjustment = Number($("#txt_AssessableAdjustment").val());
- var subtotal = grosstotal - totalDiscountAmount + assessableadjustment;
- subtotal = subtotal;
- var overalldiscount = 0;
- var taxadjustment = 0;
- if (!isNaN(Number($('#txt_TaxAdjustment').val()))) {
- taxadjustment = Number($('#txt_TaxAdjustment').val());
- }
- totaltax = Number(totaltax) + Number(taxadjustment);
- $('#totalTax').html(totaltax);
- $('#grosstotal').html(grosstotal);
- $('#totalItemDiscount').html(itemdiscount_total);
- $('#totalDiscount').html(totalDiscountAmount);
- $("#totalinvoiceqty").html(totalQty);
- var expense = 0;
- if (!isNaN(Number($('#txtOverallExpenseAmount').val()))) {
- expense = Number($('#txtOverallExpenseAmount').val());
- $("#totalexpense").text(expense);
- }
- var adjustment = 0;
- if (!isNaN(Number($('#txt_Adjustment').val()))) {
- adjustment = Number($('#txt_Adjustment').val());
- $("#span_Adjustment").text(adjustment);
- }
- var nettotal = Number(subtotal) + Number(addexpenserow_total) - Number(overalldiscount) - Number(netadddiscountrow_total) + Number(adjustment);
- if ($("#hfId_IsTaxInclusive").val() == "false")
- nettotal += Number(totaltax);
- if ($("#hfId_IsTaxInclusive").val() == "true") {
- subtotal = Number(subtotal) - Number(totalTaxAmount);
- }
- $('#subtotal').html(subtotal);
- $('.nettotal').html(nettotal);
- ItemDetails.Instance().totalAdjustment();
- }
- totalAdjustment() {
- if ($('#chk_AutoAdjustment').is(':checked')) {
- var total = $('.nettotal').text();
- var splitTotal = total.split('.');
- var AdjustmentValue = 0;
- var splitedAdjestment = 0;
- if (!isNaN(Number($('#txt_Adjustment').val()))) {
- AdjustmentValue = Number($('#txt_Adjustment').val());
- }
- if (Number(splitTotal[1]) > 0) {
- if (Number(splitTotal[1]) >= 50) {
- splitedAdjestment = (100 - Number(splitTotal[1])) / 100;
- AdjustmentValue += splitedAdjestment;
- $('#txt_Adjustment').val(Number(AdjustmentValue).toFixed(2)).blur();
- }
- else {
- splitedAdjestment = Number(splitTotal[1]) / 100;
- AdjustmentValue -= splitedAdjestment;
- $('#txt_Adjustment').val(Number(AdjustmentValue).toFixed(2)).blur();
- }
- }
- }
- }
- itemsAutoComplete(element) {
- Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("tenants/themes/default/components/details/details.js", function () {
- });
- var txtAutoSearchCtrl = element.find(".prodName");
- var hdnOrderItemId = element.find(".orderItemId");
- var hdnDcItemId = element.find(".dcItemId");
- var hdnSelectedItemId = element.find(".selectedItemId");
- if (hdnSelectedItemId.val() != 0 && hdnSelectedItemId.val() != "") {
- this.itemIds.push(hdnSelectedItemId.val());
- element.find(".hfoldItemId").val(hdnSelectedItemId.val());
- }
- this.itemIds = [];
- var hdnAutoId = hdnSelectedItemId;
- var orderid = $("#hf_" + $("#hfLayout_InstalledPageId").val() + "_OrderId").val();
- var dcid = $("#hf_" + $("#hfLayout_InstalledPageId").val() + "_DcId").val();
- var invoiceid = $("#hf_" + $("#hfLayout_InstalledPageId").val() + "_InvoiceId").val();
- if (invoiceid == undefined || invoiceid == "null")
- invoiceid = 0;
- var url = "";
- var OrdersettingId = 0;
- var url = _appsettings.server_url() + '/apis/v4/unibase/transact/items/getitems/itemids/' + ',' + '/lobid/' + 100284890000001;
- AutoCompleteHelper.getHelper().Create("#txt_item_" + this.rowIndex, "#hf_txtitem_" + this.rowIndex, url, function (response) {
- var data = response;
- ItemDetails.Instance().update_total();
- });
- element.find(".div_SplitInvoiceItem").removeClass("hidden");
- ItemDetails.instance.loadTaxGroupAutoComplete(element);
- }
- RemoveItem(element) {
- var rowIndex = element.find(".rowIndex").val();
- element.find(".delete").on('click', function () {
- var _this = element.find(".delete");
- var invoiceitemid = _this.parents('.item-row').find(".selectedInvoiceItemId").val();
- _this.parents('.item-row').remove();
- var count = 1;
- $(".InvoiceItems").find(".item-addedrow").each(function () {
- $(this).find(".rowIndex").val(count);
- $(this).find(".selectedItemId").attr("id", "hf_txtitem_" + count);
- $(this).find(".prodName").attr("id", "txt_item_" + count);
- $(this).attr("id", "div_itemAddedRow_" + count);
- count++;
- });
- });
- }
- deleteRow(rowid, itemid) {
- var ids = this.deletedItems.push(itemid);
- ItemDetails.instance.deleteInvoiceItem(ids);
- }
- deleteInvoiceItem(invItemIds) {
- for (var i = 0; i < invItemIds.length; i++) {
- }
- }
- static Instance() {
- if (this.instance === undefined) {
- this.instance = new ItemDetails();
- }
- return this.instance;
- }
- }
- Controls.ItemDetails = ItemDetails;
- })(Controls = Forms.Controls || (Forms.Controls = {}));
- })(Forms = Unibase.Forms || (Unibase.Forms = {}));
- })(Unibase || (Unibase = {}));
|