src/ApplicationBundle/Resources/views/modals/input_forms/add_expense.html.twig line 1

Open in your IDE?
  1. <!-- Modal -->
  2. {% if not userRestrictions is defined %}
  3.     {% set  userRestrictions=''|getUserRestrictions %}
  4. {% endif %}
  5. <div class="modal fade" id="newExpenseModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  6.     <div class="modal-dialog modal-lg" role="document">
  7.         <form class="form-horizontal addCreatedByDataForm expenseForm" method="post" action="{{ url('add_expense') }}"
  8.               enctype="multipart/form-data">
  9.             <div class="modal-content">
  10.                 <div class="modal-header">
  11.                     <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  12.                         <span aria-hidden="true">&times;</span>
  13.                     </button>
  14.                     <h4 class="modal-title" id="myModalLabel">Add New Expense</h4>
  15.                 </div>
  16.                 <div class="modal-body">
  17.                     <div class="row clearfix">
  18.                         <div class="col-md-6 col-sm-12">
  19.                             <div class="form-group">
  20.                                 <label for="inputEmail3" class="col-sm-4 control-label">Documents</label>
  21.                                 <div class="col-sm-8">
  22.                                     <label class="btn  btn-file ">
  23.                                     <label class="btn  btn-file ">
  24.                                         <i class="fa fa-file"></i>
  25.                                         Upload Images/Documents
  26.                                         <input type="file" class="form-control exp_att_file" name="file[]"
  27.                                                placeholder="File"
  28.                                                id="sig_file"
  29.                                                multiple/>
  30.                                     </label>
  31.                                 </div>
  32.                             </div>
  33.                             <div class="form-group">
  34.                                 <label for="inputEmail3" class="col-sm-4 control-label">Expense Date</label>
  35.                                 <div class="col-sm-8">
  36.                                     <input name="expense_date" type="text" class="form-control add_basic_day_picker"
  37.                                            placeholder="Date" value="{{ ''|date('F d, Y') }}" style=""/>
  38.                                 </div>
  39.                             </div>
  40.                             <div class="form-group">
  41.                                 <label for="inputEmail3" class="col-sm-4 control-label">Expense Type</label>
  42.                                 <div class="col-sm-8">
  43.                                     <select
  44.                                             class="form-control selectize_me  filter_by_this" name="expense_type"
  45.                                             id="expenseModalExpenseType">
  46.                                         {# {% for category in itemgroup %} #}
  47.                                         <option value="0">General</option>
  48.                                         <option value="1">Against Purchase
  49.                                         </option>
  50.                                         <option value="2">Against Sales/Project</option>
  51.                                         <option value="3">Against Sales Lead/Tender</option>
  52.                                         {# {% endfor %} #}
  53.                                     </select>
  54.                                 </div>
  55.                             </div>
  56.                             <div class="form-group" style="display: none;">
  57.                                 <label for="inputEmail3" class="col-sm-4 control-label">Record As</label>
  58.                                 {% set expSubTypes=''|getExpSubTypes %}
  59.                                 <div class="col-sm-8">
  60.                                     <select
  61.                                             class="form-control selectize_me" name="expense_sub_type">
  62.                                         {# {% for category in itemgroup %} #}
  63.                                         {% for g,d in expSubTypes %}
  64.                                             <option value="{{ g }}">{{ d.alias }}</option>
  65.                                         {% endfor %}
  66.                                         {# <option value="2">As Advance</option
  67.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 > #}
  68.                                         {# <option value="3">As Loan</option
  69.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 > #}
  70.                                         {# {% endfor %} #}
  71.                                     </select>
  72.                                 </div>
  73.                             </div>
  74.                             {#                    <div class="form-group"> #}
  75.                             {#                        <label for="inputEmail3" class="col-sm-4 control-label">Expense Sub Type</label> #}
  76.                             {#                        <div class="col-sm-8"> #}
  77.                             {#                            <select class="form-control selectize_me" name="expense_sub_type"> #}
  78.                             {#                                <option value="1">Food</option> #}
  79.                             {#                            </select> #}
  80.                             {#                        </div> #}
  81.                             {#                    </div> #}
  82.                             <div class="form-group">
  83.                                 <label for="inputEmail3" class="col-sm-4 control-label">Amount</label>
  84.                                 <div class="col-sm-8">
  85.                                     <input type="number" name="expense_amount" step="0.01" class="form-control"
  86.                                            id="expense_amount" placeholder="Amount"/>
  87.                                 </div>
  88.                             </div>
  89.                             <div class="form-group filter filter-1">
  90.                                 <label for="inputEmail3" class="col-sm-4 control-label">Advance Amount</label>
  91.                                 <div class="col-sm-8">
  92.                                     <input type="number" name="prev_advance_amount" step="0.01" class="form-control"
  93.                                            id="prev_advance_amount" placeholder="Amount" value="0"/>
  94.                                 </div>
  95.                             </div>
  96.                             <div class="form-group  ">
  97.                                 <label for="inputEmail3" class="col-sm-4 control-label">Expense name and Cost
  98.                                     Centre</label>
  99.                                 <div
  100.                                         class="col-sm-8">
  101.                                     {# {% set head_list=''|GetParentLedgerHeads %} #}
  102.                                     {% set
  103.                                         exp_head_list=''|GetParentLedgerHeads('exp') %}
  104.                                     <select class="form-control selectize_me change_check_narration" name="expense_id"
  105.                                             id="expenseModalExpenseId">
  106.                                         {% for head in exp_head_list %}
  107.                                             <option value="{{ head['id'] }}">{{ head["text"] }}</option>
  108.                                         {% endfor %}
  109.                                     </select>
  110.                                     {% set cc_list=''|GetCostCenterHeads %}
  111.                                     <select class="form-control selectize_me " name="ccId">
  112.                                         <option value="">Select Cost Centre</option>
  113.                                         <option value="0">None</option>
  114.                                         {% for entry in cc_list %}
  115.                                             <option value="{{ entry.id }}">{{ entry.text }}
  116.                                             </option>
  117.                                         {% endfor %}
  118.                                     </select>
  119.                                     <input type="text" name="expense_to_note_0" class="form-control"
  120.                                            placeholder="Notes about this"/>
  121.                                 </div>
  122.                             </div>
  123.                             <div class="form-group filter filter-2">
  124.                                 <label for="inputEmail3" class="col-sm-4 control-label">Sales Order/Project</label>
  125.                                 <div class="col-sm-8">
  126.                                     {#                            {% set so_list=''|SoList %} #}
  127.                                     <select class="form-control change_check_narration soIdExp" name="soId"
  128.                                             id="expenseModalSoId">
  129.                                         {#                                {% for entry in so_list %} #}
  130.                                         {#                                    <option value="{{ entry.salesorderId }}">{{ entry.documentHash }}</option> #}
  131.                                         {#                                {% endfor %} #}
  132.                                     </select>
  133.                                     <input type="text" name="expense_to_note_2" class="form-control"
  134.                                            placeholder="Notes about this"/>
  135.                                 </div>
  136.                             </div>
  137.                             <div class="form-group filter filter-3">
  138.                                 <label for="inputEmail3" class="col-sm-4 control-label">Lead/Bid</label>
  139.                                 <div class="col-sm-8">
  140.                                     {#                            {% set so_list=''|SoList %} #}
  141.                                     <select class="form-control change_check_narration leadIdExp" name="leadId"
  142.                                             id="expenseModalLeadId">
  143.                                         {#                                {% for entry in so_list %} #}
  144.                                         {#                                    <option value="{{ entry.salesorderId }}">{{ entry.documentHash }}</option> #}
  145.                                         {#                                {% endfor %} #}
  146.                                     </select>
  147.                                     <input type="text" name="expense_to_note_3" class="form-control"
  148.                                            placeholder="Notes about this"/>
  149.                                 </div>
  150.                             </div>
  151.                             <div class="form-group filter filter-1">
  152.                                 <label for="inputEmail3" class="col-sm-4 control-label">Purchase Order</label>
  153.                                 <div class="col-sm-8">
  154.                                     {#                            {% set po_list=''|PoList %} #}
  155.                                     <select class="form-control  change_check_narration poIdExp" name="poId"
  156.                                             id="expenseModalPoId">
  157.                                     </select>
  158.                                     <input type="text" name="expense_to_note_1" class="form-control"
  159.                                            placeholder="Notes about this"/>
  160.                                 </div>
  161.                             </div>
  162.                             <div class="form-group filter filter-1">
  163.                                 <label for="inputEmail3" class="col-sm-4 control-label">Invocation Strategy</label>
  164.                                 <div class="col-sm-8">
  165.                                     <select class="form-control selectize_me " name="expenseInvocationStrategyOnGrn">
  166.                                         <option value="1">Previous Received Product(s) if available (same Order)
  167.                                         </option>
  168.                                         <option value="2">Hold for next GRN</option>
  169.                                     </select>
  170.                                 </div>
  171.                             </div>
  172.                             <div class="form-group filter filter-1">
  173.                                 <label for="inputEmail3" class="col-sm-4 control-label">Invocation Type on Received
  174.                                     Items</label>
  175.                                 <div class="col-sm-8">
  176.                                     <select class="form-control selectize_me " name="expenseInvocationTypeOnItems">
  177.                                         <option value="1">Full on Received Products</option>
  178.                                         <option value="2">Weighted on PO amount</option>
  179.                                     </select>
  180.                                 </div>
  181.                             </div>
  182.                             <div class="form-group ">
  183.                                 <label for="inputEmail3" class="col-sm-4 control-label">Balance against head</label>
  184.                                 <div
  185.                                         class="col-sm-8">
  186.                                     {# {% set head_list='pv'|GetParentLedgerHeads('',0) %} #}
  187.                                     {% set
  188.                                         head_list='pv'|GetParentLedgerHeads('') %}
  189.                                     {# {{
  190.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             dump(head_list.found_id)
  191.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           }} #}
  192.                                     {# {{ dump(head_list.DEBIT_HEADS_BY_ID) }} #}
  193.                                     <select class="form-control  expense_change_check_number expenseToBePaidTo childOnly"
  194.                                             name="expense_to_be_paid_to" id="expenseModalToBePaidTo">
  195.                                         {#                                        <option value="">Select</option> #}
  196.                                     </select>
  197.                                     <input type="text" name="expense_from_note" class="form-control"
  198.                                            placeholder="Notes about this"/>
  199.                                 </div>
  200.                             </div>
  201.                             <div class="form-group" style="">
  202.                                 <label for="inputEmail3" class="col-sm-4 control-label">Pay From (optional)</label>
  203.                                 <div class="col-sm-8">
  204.                                     {% set head_list='pv'|GetParentLedgerHeads %}
  205.                                     <select class="form-control selectize_me expense_change_check_number"
  206.                                             name="expense_from"
  207.                                             id="expenseModalPayFrom">
  208.                                         <option value="">Select</option>
  209.                                         {% if head_list.CREDIT_HEADS is defined %}
  210.                                             {% for head in
  211.                                                 head_list.CREDIT_HEADS %}
  212.                                                 <option value="{{ head['id'] }}">{{ head["text"] }}</option>
  213.                                             {% endfor %}
  214.                                         {% endif %}
  215.                                     </select>
  216.                                     {# <input type="text" name="expense_from_note" class="form-control" placeholder="Notes about this"/> #}
  217.                                 </div>
  218.                             </div>
  219.                             <div class="form-group ">
  220.                                 <label for="inputEmail3" class="col-sm-4 control-label">Cheque No.</label>
  221.                                 <div class="col-sm-8">
  222.                                     <select name="check_id" class="form-control" id="expense_check_id"
  223.                                     ></select>
  224.                                 </div>
  225.                             </div>
  226.                             <div class="form-group filter expense_check_number_div">
  227.                                 <label for="inputEmail3" class="col-sm-4 control-label">Check Date</label>
  228.                                 <div class="col-sm-8">
  229.                                     <input type="hidden" name="check_number" class="form-control"
  230.                                            id="expense_check_number_here"
  231.                                            placeholder=""/>
  232.                                     <input name="check_date" type="text" class="form-control add_basic_day_picker"
  233.                                            placeholder="Date" value="{{ ''|date('F d, Y') }}" style=""/>
  234.                                 </div>
  235.                             </div>
  236.                             <div class="form-group filter expense_check_number_div">
  237.                                 <label for="inputEmail3" class="col-sm-4 control-label">Check Narration</label>
  238.                                 <div class="col-sm-8">
  239.                                     <input type="text" name="check_narration" class="form-control"
  240.                                            id="expense_check_narration"
  241.                                            placeholder="Check Narration (default)" value=""/>
  242.                                 </div>
  243.                             </div>
  244.                             <div class="form-group filter filter-default filter-1">
  245.                                 <label for="inputEmail3" class="col-sm-4 control-label"></label>
  246.                                 <div class="col-sm-8">
  247.                                     <div class="checkbox checkbox-styled" bis_skin_checked="1">
  248.                                         <label>
  249.                                             <input type="checkbox" name="auto_balance_1" value="1"
  250.                                                    id="exp_check_auto_balance"
  251.                                                    checked>
  252.                                             <span>Automatically Balance Invoice and Order</span>
  253.                                         </label>
  254.                                     </div>
  255.                                 </div>
  256.                             </div>
  257.                         </div>
  258.                         <div class="col-md-6 col-sm-12">
  259.                             <div class="form-group filter filter-1">
  260.                                 <label for="inputEmail3" class="col-sm-4 control-label">Cost Distribution</label>
  261.                                 <div class="col-sm-8">
  262.                                     <div class="checkbox checkbox-styled" bis_skin_checked="1">
  263.                                         <label>
  264.                                             <input type="checkbox" name="exp_check_expense_distribution_on_product"
  265.                                                    value="1" id="exp_check_expense_distribution_on_product">
  266.                                             <span>Distribute Expense Individually</span>
  267.                                         </label>
  268.                                     </div>
  269.                                 </div>
  270.                             </div>
  271.                             <div class="form-group exp_distribution_on_product_pre_div filter filter-1">
  272.                                 <label for="inputEmail3" class="col-sm-4 control-label">Product</label>
  273.                                 <div class="col-sm-4 ">%</div>
  274.                                 <div class="col-sm-4 ">Amount</div>
  275.                             </div>
  276.                             <div class="form-group exp_distribution_on_product_post_div filter  filter-1">
  277.                                 <label for="inputEmail3" class="col-sm-4 control-label">Total</label>
  278.                                 <div class="col-sm-4 exp_total_distribution_percentage"></div>
  279.                                 <div class="col-sm-4 exp_total_distribution_amount"></div>
  280.                             </div>
  281.                             <div class="form-group ">
  282.                                 <label for="inputEmail3" class="col-sm-4 control-label">Description/Narration</label>
  283.                                 <div
  284.                                         class="col-sm-8 desc_cont">
  285.                                     <textarea name="description" class="form-control attach_ckeditor"
  286.                                               rows="2"></textarea>
  287.                                 </div>
  288.                             </div>
  289.                         </div>
  290.                     </div>
  291.                 </div>
  292.                 <div class="modal-footer">
  293.                     <button type="button" class="btn btn-default" data-dismiss="modal">
  294.                         Close
  295.                     </button>
  296.                     <button type="submit" class="btn btn-primary expenseModalSubmit">Save</button>
  297.                 </div>
  298.             </div>
  299.         </form>
  300.     </div>
  301. </div>
  302. <style>
  303.     #newExpenseModal .form-control.selectize-control {
  304.         border-bottom: 1px solid rgba(12, 12, 12, 0.12);
  305.         height: auto;
  306.         max-height: 31px;
  307.     }
  308.     #newExpenseModal input.form-control {
  309.         font-size: 14px;
  310.         font-weight: bold;
  311.         padding-left: 12px;
  312.     }
  313.     #newExpenseModal .selectize-dropdown,
  314.     #newExpenseModal .selectize-input,
  315.     #newExpenseModal .selectize-input input {
  316.         color: #0c0c0c;
  317.         font-weight: bold;
  318.         font-size: 14px;
  319.     }
  320.     #newExpenseModal .selectize-input.not-full input {
  321.         /*color: #0c0c0c;*/
  322.         /*font-weight: normal;*/
  323.         /*font-size: 14px;*/
  324.     }
  325.     #newExpenseModal .selectize-input.has-items .item {
  326.         line-height: 1;
  327.         height: 14px;
  328.         overflow: hidden;
  329.     }
  330.     #newExpenseModal .selectize-input.has-items .item:hover {
  331.         overflow: visible;
  332.     }
  333.     /*#newExpenseModal .form-control.selectize-control:hover {*/
  334.     /*    border-bottom: 1px solid rgba(12, 12, 12, 0.12);*/
  335.     /*    height: auto;*/
  336.     /*    max-height: unset !important;*/
  337.     /*    min-height: 0px !important;*/
  338.     /*}*/
  339.     @media (min-width: 769px) {
  340.         #newExpenseModal .desc_cont {
  341.             padding-top: 5.5px;
  342.         }
  343.     }
  344. </style>
  345. <script>
  346.     var canSelectAnyHeadForExpenseBalancing ={{ userRestrictions.canSelectAnyHeadForExpenseBalancing is defined?userRestrictions.canSelectAnyHeadForExpenseBalancing:1 }}
  347.     var newExpenseModalSystem =
  348.         {
  349.             modalMode: 'standalone', //or edit
  350.             soSelector: {},
  351.             leadSelector: {},
  352.             checkSelector: {},
  353.             poSelector: {},
  354.             soData: {},
  355.             leadData: {},
  356.             checkData: {},
  357.             poData: {},
  358.             toBeBalancedFromSelector: {},
  359.             headSelector: {},
  360.             toBeBalancedFromSelectorFilterGenerator: function () {
  361.                 if ($('#expenseModalExpenseType').val() == 1) //purchase
  362.                 {
  363.                     var markers = [
  364.                         '_ALL_',
  365.                         // '_CASP_',
  366.                         // '_NCASP_',
  367.                         // '_CLP_',
  368.                         // '_NCLP_',
  369.                         // '_SPAH_',
  370.                         // '_SPAH_',
  371.                     ]
  372.                     return markers.join(',')
  373.                 } else if ($('#expenseModalExpenseType').val() == 2) //sales
  374.                 {
  375.                     var markers = [
  376.                         '_ALL_',
  377.                         // '_CASP_',
  378.                         // '_CLP_',
  379.                         // '_NCLP_',
  380.                         // // '_NCASP_',
  381.                         // '_SPAH_',
  382.                         // '_IPAH_',
  383.                     ]
  384.                     return markers.join(',')
  385.                 } else {
  386.                     var markers = [
  387.                         '_ALL_',
  388.                         // '_CASP_',
  389.                         // // '_NCASP_',
  390.                         // '_CLP_',
  391.                         // '_NCLP_',
  392.                         // '_SPAH_',
  393.                         // '_IPAH_',
  394.                     ]
  395.                     return markers.join(',')
  396.                 }
  397.             },
  398.             refreshDistributedProductListForExpenseBalancing: function () {
  399.                 $('.exp_distribution_row').remove();
  400.                 // alert('here')
  401.                 if (newExpenseModalSystem.poSelector.getValue() == '')
  402.                     newExpenseModalSystem.distributedProductAmountTotalRecalculate();
  403.                 else if ($('#exp_check_expense_distribution_on_product').prop('checked') == true) {
  404.                     var pika_ind_id = '_NONE_'
  405.                     $.ajax({
  406.                         url: BaseURL + "select_data_ajax",
  407.                         type: 'POST',
  408.                         dataType: 'json',
  409.                         // render: {
  410.                         //     option: function (item, escape) {
  411.                         //         return '<div class="p-l-10 p-r-10">'
  412.                         //             + '<h6> #'+escape(item[value])+' ' + escape(item[document_hash]) + ' -- '+ escape(item[lc_number])+'</h6> '
  413.                         //             + '<span>Supplier:' + escape(item[supplier_name]) + '</span> '
  414.                         //             //+ '<span>Name:'+item.name+'</span> '
  415.                         //             //+ '<span>DEBUG:'+item.score+'</span>'
  416.                         //             + '</div>';
  417.                         //     }
  418.                         // },
  419.                         data: {
  420.                             //returnJson: 1,
  421.                             //sessionData: sessionData
  422.                             query: '_EMPTY_',
  423.                             tableName: "purchase_order_item",
  424.                             valueField: "id",
  425.                             textField: "rendered_text",
  426.                             entity_group: 0,
  427.                             selectorId: '_NONE_',
  428.                             isMultiple: 0,
  429.                             dataId: pika_ind_id,
  430. //
  431.                             renderTextFormat: "#__product_name__ ",
  432.                             andConditions: [],
  433.                             andOrConditions: [
  434.                                 // // {type: "=", field: "supplier_id", value: isNaN(query) ? '' : query},
  435.                                 // {type: "=", field: "purchase_order_id", value: isNaN(query) ? '' : query},
  436.                                 // {type: "like", field: "document_hash", value: query},
  437.                                 // {type: "like", field: "acc_suppliers_0.supplier_name", value: query},
  438.                                 // {type: "like", field: "lc_number", value: query},
  439.                             ],
  440.                             mustConditions: [
  441.                                 {
  442.                                     type: "=",
  443.                                     field: "purchase_order_id",
  444.                                     value: newExpenseModalSystem.poSelector.getValue()
  445.                                 },
  446.                             ],
  447.                             joinTableData: [
  448.                                 {
  449.                                     tableName: "inv_products",
  450.                                     joinFieldPrimary: "product_id",
  451.                                     joinOn: 'id',
  452.                                     tableJoinType: 'left join',
  453.                                     // fieldJoinType: '=',
  454.                                     selectPrefix: 'product_',
  455.                                     selectFieldList: [
  456.                                         'name'
  457.                                     ]
  458.                                 },
  459.                                 {
  460.                                     tableName: "acc_service",
  461.                                     joinFieldPrimary: "service_id",
  462.                                     joinOn: 'service_id',
  463.                                     tableJoinType: 'left join',
  464.                                     // fieldJoinType: '=',
  465.                                     // selectPrefix: 'supplier_',
  466.                                     selectFieldList: [
  467.                                         'service_name'
  468.                                     ]
  469.                                 },
  470.                             ],
  471.                             convertToObject: [
  472. //                            'accessories', 'issues'
  473.                             ],
  474.                             skipDefaultCompanyId: 1
  475.                             // setDataForSingle: 1,
  476.                         },
  477.                         error: function () {
  478.                             // callback();
  479.                         },
  480.                         success: function (res) {
  481.                             for (var exp_j = 0; exp_j < res.data.length; exp_j++) {
  482.                                 var productName = res.data[exp_j].product_name;
  483.                                 var poItemId = res.data[exp_j].id;
  484.                                 var toAddStr = '<div class="form-group filter exp_distribution_row">' +
  485.                                     '<label for="inputEmail3" class="col-sm-4 control-label">' + productName + '</label>' +
  486.                                     '<div class="col-sm-4">' +
  487.                                     '<input type="number" ' +
  488.                                     'name="exp_distribution_percentage[]" ' +
  489.                                     'class="form-control exp_distribution_percentage exp_distribution_percentage' + poItemId + '" ' +
  490.                                     'data-id="' + poItemId + '"' +
  491.                                     'id="exp_distribution_percentage' + poItemId + '" ' +
  492.                                     'value=""/>' +
  493.                                     '</div>' +
  494.                                     '<div class="col-sm-4">' +
  495.                                     '<input type="hidden" ' +
  496.                                     'name="exp_distribution_poitemId[]" ' +
  497.                                     'class="form-control exp_distribution_poitemId exp_distribution_poitemId' + poItemId + '" ' +
  498.                                     'data-id="' + poItemId + '"' +
  499.                                     'id="exp_distribution_poitemId' + poItemId + '" ' +
  500.                                     'value="' + poItemId + '"/>' +
  501.                                     '<input type="number" ' +
  502.                                     'name="exp_distribution_amount[]" ' +
  503.                                     'class="form-control exp_distribution_amount exp_distribution_amount' + poItemId + '" ' +
  504.                                     'data-id="' + poItemId + '"' +
  505.                                     'id="exp_distribution_amount' + poItemId + '" ' +
  506.                                     'value=""/>' +
  507.                                     '</div>' +
  508.                                     '</div>';
  509.                                 $('.exp_distribution_on_product_pre_div').after(toAddStr);
  510.                             }
  511.                             newExpenseModalSystem.distributedProductAmountTotalRecalculate();
  512.                         }
  513.                     });
  514.                 } else
  515.                     newExpenseModalSystem.distributedProductAmountTotalRecalculate();
  516.             },
  517.             distributedProductAmountTotalRecalculate: function (changeExpAmount) {
  518.                 changeExpAmount = changeExpAmount || 0
  519.                 var total_distribution_percentage = 0;
  520.                 var total_distribution_amount = 0;
  521.                 $('.exp_distribution_percentage').each(function (ind_exp, elem) {
  522.                     if (elem.val() != '')
  523.                         total_distribution_percentage += (1 * elem.val());
  524.                 })
  525.                 $('.exp_distribution_amount').each(function (ind_exp, elem) {
  526.                     if (elem.val() != '')
  527.                         total_distribution_amount += (1 * elem.val());
  528.                 })
  529.                 $('.exp_total_distribution_amount').text(total_distribution_amount.toFixed(2));
  530.                 if (changeExpAmount == 1)
  531.                     $('#expense_amount').val(total_distribution_amount.toFixed(2));
  532.                 $('.exp_total_distribution_percentage').text(total_distribution_percentage.toFixed(2));
  533.             },
  534.             checkAndAddExpenseDataToList: function () {
  535.                 var validated = true;
  536.                 if (validated == true)
  537.                     addExpenseRow();
  538.             },
  539.             triggerExpenseModal: function (config) {
  540.                 config = config || {
  541.                     soItemFound: 0,
  542.                     soItemDelivered: 0,
  543.                     id: 0,
  544.                     alias: '',
  545.                     note: '',
  546.                     unit: 0,
  547.                     warranty: 0,
  548.                     unitTypeId: 0,
  549.                     unit_price: 0,
  550.                     fdm: '',
  551.                     product_name: '',
  552.                     soItemId: 0,
  553.                     total_price: 0,
  554.                     isForeignItem: isForeignItem,
  555.                     isSegment: isSegment,
  556.                 };
  557.                 var dataRow =
  558.                     {
  559.                         currencyId: 0,
  560.                         currencyMultiplyRate: 1,
  561.                         currencyText: '',
  562.                         scope: '',   //scope type 0/null/1 is own 2: V3endor 3:entity 4 :others
  563.                         scopeHolderId: '',   //Supplier Id or APp Id
  564.                         scopeHolderName: '',   //
  565.                         scopeDescription: '',   //
  566.                     }
  567.                 $.each(config, function (key, valueObj) {
  568.                     dataRow[key] = valueObj;
  569.                 });
  570.                 // if (typeof dataRow.isSegment !== 'undefined')
  571.                 //     isSegment = dataRow.isSegment;
  572.                 ///populate data here
  573.                 //then trigger modal
  574.                 $('#newExpenseModal').modal('show');
  575.             },
  576.         }
  577.     const toBase64 = file => new Promise((resolve, reject) => {
  578.         const reader = new FileReader();
  579.         reader.readAsDataURL(file);
  580.         reader.onload = () => resolve(reader.result);
  581.         reader.onerror = reject;
  582.     });
  583.     // function toDataURL(url, callback) {
  584.     //     var xhr = new XMLHttpRequest();
  585.     //     xhr.onload = function() {
  586.     //         var reader = new FileReader();
  587.     //         reader.onloadend = function() {
  588.     //             callback(reader.result);
  589.     //         }
  590.     //         reader.readAsDataURL(xhr.response);
  591.     //     };
  592.     //     xhr.open('GET', url);
  593.     //     xhr.responseType = 'blob';
  594.     //     xhr.send();
  595.     // }
  596.     //
  597.     // toDataURL('https://www.gravatar.com/avatar/d50c83cc0c6523b4d3f6085295c953e0', function(dataUrl) {
  598.     //     console.log('RESULT:', dataUrl)
  599.     // })
  600.     const edenAiUrl = "https://api.edenai.run/v2/workflow/4261f761-07b5-4ee3-b81e-a55733a81e8c/execution/";
  601.     const edenAiUrlDirect = "https://api.edenai.run/v2/ocr/financial_parser";
  602.     const edenApiKey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNDIwZTEwNDktOTFjNC00YzZhLWJhNjEtZDk3MDhjZWI4MjFjIiwidHlwZSI6ImFwaV90b2tlbiJ9.IXXp0DsFHyCrtkY0Ck1M9CQkXH8ZxCOfVs4lpHhOy2s"; // Replace with your actual API key
  603.     var executionDetailsUrl = '';
  604.     var edenAiExecutionId = 0;
  605.     var edenAiRowIdByExecutionId = {};
  606.     var parseDataPending = [
  607.         //{rowId :1,filepath:''}
  608.     ];
  609.     var exp_head_list ={{ exp_head_list|json_encode|raw }};
  610.     function nextParseOcr() {
  611.         if (parseDataPending.length > 0) {
  612.             initiateOcr()
  613.         }
  614.     }
  615.     function initiateOcr(selectorId, fileIndex, refRowId, fileUrl) {
  616.         refRowId = refRowId || '_NONE_';
  617.         fileIndex = fileIndex || 0;
  618.         fileUrl = fileUrl || '';
  619.         fileUrl = '{{ absolute_url(path('dashboard')) }}' + parseDataPending[0]['filePath']
  620.         const options = {
  621.             method: 'POST',
  622.             headers: {
  623.                 accept: 'application/json',
  624.                 'content-type': 'application/json',
  625.                 authorization: `Bearer ${edenApiKey}`
  626.             },
  627.             body: JSON.stringify({
  628.                 response_as_dict: false,
  629.                 attributes_as_list: false,
  630.                 show_base_64: false,
  631.                 show_original_response: false,
  632.                 document_type: 'invoice',
  633.                 convert_to_pdf: false,
  634.                 file_url: fileUrl,
  635.                 // providers: ['google'],
  636.                 providers: ['amazon'],
  637.                 language: 'en'
  638.             })
  639.         };
  640.         // const payload = { file: fileData }; // Replace with actual file data
  641.         fetch('https://api.edenai.run/v2/ocr/financial_parser', options)
  642.             .then(res => res.json())
  643.             .then(res => {
  644.                 console.log(res)
  645.                 if (newExpenseModalSystem.modalMode == 'standalone') {
  646.                     $('#newExpenseModal .trigger_ckeditor').html(
  647.                         '<p><b>Merchant Name:</b> ' + executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].merchant_information.name + '</p>' +
  648.                         '<p><b>Merchant Address:</b> ' + executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].merchant_information.address + '</p>' +
  649.                         '<p><b>Merchant Phone:</b> ' + executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].merchant_information.phone + '</p>'
  650.                     );
  651.                     $('#newExpenseModal textarea').val(
  652.                         '<p><b>Merchant Name:</b> ' + executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].merchant_information.name + '</p>' +
  653.                         '<p><b>Merchant Address:</b> ' + executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].merchant_information.address + '</p>' +
  654.                         '<p><b>Merchant Phone:</b> ' + executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].merchant_information.phone + '</p>'
  655.                     );
  656.                     $('#newExpenseModal #expense_amount').val(
  657.                         1 * (executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].payment_information.amount_due) +
  658.                         1 * (executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].payment_information.total_tax)
  659.                     )
  660.                     if (executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].document_metadata.document_type == 'restaurant_statement') {
  661.                         for (var hopo = 0; hopo < exp_head_list.length; hopo++) {
  662.                             if ((exp_head_list[hopo]['text']).search(/food/i) != -1) {
  663.                                 newExpenseModalSystem.headSelector.setValue(exp_head_list[hopo]['id'])
  664.                             }
  665.                         }
  666.                     }
  667.                 } else {
  668.                     if (parseDataPending.length > 0) {
  669.                         populateExpRowBasedOnOcr(res[0].extracted_data[0], parseDataPending[0]['rowId'])
  670.                         parseDataPending.shift(); // removes the first element, which is 1
  671.                     }
  672.                     if (parseDataPending.length > 0) {
  673.                         nextParseOcr()
  674.                         // console.log(parseDataPending);
  675.                     }
  676.                 }
  677.             })
  678.             .catch(err => console.error(err));
  679.     }
  680.     function parseOcr(ffEdenAiExecutionId) {
  681.         // const payload = { file: fileData }; // Replace with actual file data
  682.         (async () => {
  683.             try {
  684.                 const ggExecutionDetailsUrl = `https://api.edenai.run/v2/workflow/4261f761-07b5-4ee3-b81e-a55733a81e8c/execution/${ffEdenAiExecutionId}/`
  685.                 const detailsResponse = await fetch(ggExecutionDetailsUrl, {
  686.                     headers: {
  687.                         "Content-Type": "application/json",
  688.                         // 'Authorization': `Bearer ${edenApiKey}`
  689.                         'Authorization': `Bearer ${edenApiKey}`
  690.                     },
  691.                 });
  692.                 const executionData = await detailsResponse.json();
  693.                 // Process the execution details (detailsData) here
  694.                 console.log(executionData);
  695.                 var ggEdenAiExecutionId = executionData.id;
  696.                 if (typeof executionData.content !== 'undefined') {
  697.                     if (executionData.content.status == 'running') {
  698.                         setTimeout(function () {
  699.                             parseOcr(ggEdenAiExecutionId);
  700.                         }, 2000);
  701.                     } else if (executionData.content.status == 'success') {
  702.                         if (newExpenseModalSystem.modalMode == 'standalone') {
  703.                             $('#newExpenseModal .trigger_ckeditor').html(
  704.                                 '<p><b>Merchant Name:</b> ' + executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].merchant_information.name + '</p>' +
  705.                                 '<p><b>Merchant Address:</b> ' + executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].merchant_information.address + '</p>' +
  706.                                 '<p><b>Merchant Phone:</b> ' + executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].merchant_information.phone + '</p>'
  707.                             );
  708.                             $('#newExpenseModal textarea').val(
  709.                                 '<p><b>Merchant Name:</b> ' + executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].merchant_information.name + '</p>' +
  710.                                 '<p><b>Merchant Address:</b> ' + executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].merchant_information.address + '</p>' +
  711.                                 '<p><b>Merchant Phone:</b> ' + executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].merchant_information.phone + '</p>'
  712.                             );
  713.                             $('#newExpenseModal #expense_amount').val(
  714.                                 1 * (executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].payment_information.amount_due) +
  715.                                 1 * (executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].payment_information.total_tax)
  716.                             )
  717.                             if (executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].document_metadata.document_type == 'restaurant_statement') {
  718.                                 for (var hopo = 0; hopo < exp_head_list.length; hopo++) {
  719.                                     if ((exp_head_list[hopo]['text']).search(/food/i) != -1) {
  720.                                         newExpenseModalSystem.headSelector.setValue(exp_head_list[hopo]['id'])
  721.                                     }
  722.                                 }
  723.                             }
  724.                         } else {
  725.                             populateExpRowBasedOnOcr(executionData.content.results.ocr__financial_parser.results[0].extracted_data[0], ggEdenAiExecutionId)
  726.                         }
  727.                     } else {
  728.                     }
  729.                 }
  730.             } catch (error) {
  731.                 console.error("Error:", error);
  732.             }
  733.         })();
  734.     }
  735.     function initiateOcrBackup(selectorId, fileIndex, refRowId, fileUrl) {
  736.         refRowId = refRowId || '_NONE_';
  737.         fileIndex = fileIndex || 0;
  738.         fileUrl = fileUrl || '';
  739.         // const payload = { file: fileData }; // Replace with actual file data
  740.         (async () => {
  741.             try {
  742.                 const options = {
  743.                     method: 'POST',
  744.                     headers: {
  745.                         accept: 'application/json',
  746.                         'content-type': 'application/json',
  747.                         authorization: `Bearer ${edenApiKey}`
  748.                     },
  749.                     body: JSON.stringify({
  750.                         response_as_dict: false,
  751.                         document_type: 'auto-detect',
  752.                         file_url: fileUrl,
  753.                         language: 'en'
  754.                     })
  755.                 };
  756.                 // const options = {
  757.                 //     method: 'POST',
  758.                 //     headers: {
  759.                 //         accept: 'application/json',
  760.                 //         'content-type': 'application/json',
  761.                 //         authorization: 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNDIwZTEwNDktOTFjNC00YzZhLWJhNjEtZDk3MDhjZWI4MjFjIiwidHlwZSI6ImFwaV90b2tlbiJ9.IXXp0DsFHyCrtkY0Ck1M9CQkXH8ZxCOfVs4lpHhOy2s'
  762.                 //     },
  763.                 //     body: JSON.stringify({
  764.                 //         response_as_dict: true,
  765.                 //         attributes_as_list: false,
  766.                 //         show_base_64: true,
  767.                 //         show_original_response: false,
  768.                 //         document_type: 'invoice',
  769.                 //         convert_to_pdf: false,
  770.                 //         file_url: 'https://www.ourhoneybee.xyz/uploads/ExpenseInvoice/dc561ca5db4b674f67dacf5eb523832d.png',
  771.                 //         providers: ['google'],
  772.                 //         language: 'en'
  773.                 //     })
  774.                 // };
  775.                 //
  776.                 // fetch('https://api.edenai.run/v2/ocr/financial_parser', options)
  777.                 //     .then(res => res.json())
  778.                 //     .then(res => console.log(res))
  779.                 //     .catch(err => console.error(err));
  780.                 console.log(fileUrl)
  781.                 const responseInit = await fetch(edenAiUrl, options);
  782.                 // //formdata_start
  783.                 //
  784.                 // const formData = new FormData();
  785.                 // // formData.append('file', document.getElementById(selectorId).files[fileIndex]);
  786.                 // formData.append('refRowId', refRowId);
  787.                 // formData.append('file_url', fileUrl);
  788.                 // formData.append('language', 'en');
  789.                 //
  790.                 // console.log(fileUrl)
  791.                 //
  792.                 // const headers = {
  793.                 //     'Authorization': `Bearer ${edenApiKey}`
  794.                 // };
  795.                 //
  796.                 // const responseInit = await fetch(edenAiUrl, {
  797.                 //     method: 'POST',
  798.                 //     headers: headers,
  799.                 //     body: formData
  800.                 // });
  801.                 //
  802.                 // //form_data_end
  803.                 const executionData = await responseInit.json();
  804.                 console.log(executionData)
  805.                 // Retrieve the execution ID from the response data
  806.                 edenAiExecutionId = executionData.id;
  807.                 var ggEdenAiExecutionId = executionData.id;
  808.                 edenAiRowIdByExecutionId[edenAiExecutionId] = refRowId;
  809.                 executionDetailsUrl = `https://api.edenai.run/v2/workflow/4261f761-07b5-4ee3-b81e-a55733a81e8c/execution/${edenAiExecutionId}/`
  810.                 if (typeof executionData.content !== 'undefined') {
  811.                     if (executionData.content.status == 'running') {
  812.                         setTimeout(function () {
  813.                             parseOcr(ggEdenAiExecutionId);
  814.                         }, 2000);
  815.                     } else if (executionData.content.status == 'success') {
  816.                         if (newExpenseModalSystem.modalMode == 'standalone') {
  817.                             $('#newExpenseModal .trigger_ckeditor').html(
  818.                                 '<p><b>Merchant Name:</b> ' + executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].merchant_information.name + '</p>' +
  819.                                 '<p><b>Merchant Address:</b> ' + executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].merchant_information.address + '</p>' +
  820.                                 '<p><b>Merchant Phone:</b> ' + executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].merchant_information.phone + '</p>'
  821.                             );
  822.                             $('#newExpenseModal textarea').val(
  823.                                 '<p><b>Merchant Name:</b> ' + executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].merchant_information.name + '</p>' +
  824.                                 '<p><b>Merchant Address:</b> ' + executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].merchant_information.address + '</p>' +
  825.                                 '<p><b>Merchant Phone:</b> ' + executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].merchant_information.phone + '</p>'
  826.                             );
  827.                             $('#newExpenseModal #expense_amount').val(
  828.                                 1 * (executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].payment_information.amount_due) +
  829.                                 1 * (executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].payment_information.total_tax)
  830.                             )
  831.                             if (executionData.content.results.ocr__financial_parser.results[0].extracted_data[0].document_metadata.document_type == 'restaurant_statement') {
  832.                                 for (var hopo = 0; hopo < exp_head_list.length; hopo++) {
  833.                                     if ((exp_head_list[hopo]['text']).search(/food/i) != -1) {
  834.                                         newExpenseModalSystem.headSelector.setValue(exp_head_list[hopo]['id'])
  835.                                     }
  836.                                 }
  837.                             }
  838.                         } else {
  839.                             populateExpRowBasedOnOcr(executionData.content.results.ocr__financial_parser.results[0].extracted_data[0], ggEdenAiExecutionId)
  840.                         }
  841.                     } else {
  842.                     }
  843.                 }
  844.             } catch (error) {
  845.                 console.error("Error:", error);
  846.             }
  847.         })();
  848.     }
  849.     async function triggerOcr(selectorIdWithHash) {
  850.         const file = document.querySelector(selectorIdWithHash).files[0];
  851.         const base64String = await toBase64(file);
  852.         // Now you can use the base64String
  853.         console.log(base64String);
  854.         initiateOcr(base64String)
  855.     }
  856.     $(document).ready(function () {
  857.         newExpenseModalSystem.soSelector = $('#newExpenseModal .soIdExp').selectize({
  858.             placeholder: 'Choose a project or Order',
  859.             multiple: false,
  860. //            options: APTL.productListArray,
  861.             options: [],
  862.             valueField: 'value',
  863.             labelField: 'text',
  864.             preload: 'focus',
  865.             searchField: ['text', 'value'],
  866.             load: function (query, callback) {
  867. //                        if (!query.length) return // callback();
  868.                 if (!query.length) query = '_EMPTY_';
  869.                 var pika_ind_id = $($(this)[0].$input["0"]).attr('data-id')
  870.                 $.ajax({
  871.                     url: BaseURL + "select_data_ajax",
  872.                     type: 'POST',
  873.                     dataType: 'json',
  874.                     data: {
  875.                         //returnJson: 1,
  876.                         //sessionData: sessionData
  877.                         query: query,
  878.                         tableName: "sales_order",
  879.                         valueField: "sales_order_id",
  880.                         textField: "rendered_text",
  881.                         entity_group: 0,
  882.                         selectorId: $($(this)[0].$input["0"]).attr('id'),
  883.                         isMultiple: 0,
  884.                         dataId: pika_ind_id,
  885. //                        isMultiple: 0,
  886.                         //textField: "rendered_text",
  887. //
  888.                         renderTextFormat: "#__value__ __document_hash__ ( __client_name__ ) -  __project_name__",
  889.                         andConditions: [],
  890.                         andOrConditions: [
  891.                             {type: "=", field: "approved", value: 1},
  892.                         ],
  893.                         mustConditions: [
  894.                             {type: "=", field: "approved", value: 1},
  895.                         ],
  896.                         joinTableData: [
  897.                             {
  898.                                 tableName: "project",
  899.                                 joinFieldPrimary: "project_id",
  900.                                 joinOn: 'project_id',
  901.                                 tableJoinType: 'left join',
  902.                                 // fieldJoinType: '=',
  903.                                 // selectPrefix: '',
  904.                                 selectFieldList: [
  905.                                     'project_name', 'sales_project_asset_head_id', 'internal_project_asset_head_id'
  906.                                 ]
  907.                             },
  908.                             {
  909.                                 tableName: "acc_clients",
  910.                                 joinFieldPrimary: "client_id",
  911.                                 joinOn: 'client_id',
  912.                                 tableJoinType: 'join',
  913.                                 // fieldJoinType: '=',
  914.                                 // selectPrefix: 'client_',
  915.                                 selectFieldList: [
  916.                                     'client_name'
  917.                                 ]
  918.                             },
  919.                         ],
  920.                         convertToObject: [
  921. //                            'accessories', 'issues'
  922.                         ],
  923.                         skipDefaultCompanyId: 1,
  924.                         itemLimit: '_ALL_'
  925.                         // setDataForSingle: 1,
  926.                     },
  927.                     error: function () {
  928.                         // callback();
  929.                     },
  930.                     success: function (res) {
  931.                         newExpenseModalSystem.soData = res.dataById
  932.                         callback(res.data);
  933.                         if (res.setValueArray.length != 0 && res.selectorId != '') {
  934.                             if (res.isMultiple == 1)
  935.                                 $('#' + res.selectorId).selectize()[0].selectize.setValue(res.setValueArray)
  936.                             else
  937.                                 $('#' + res.selectorId).selectize()[0].selectize.setValue(res.setValue)
  938.                         }
  939. //                        alert('pika master')
  940.                     }
  941.                 });
  942.             },
  943.             onChange: function (value) {
  944. //                alert(value )
  945. //                newExpenseModalSystem.toBeBalancedFromSelector.setValue('')
  946. //                if(!value.length)return;
  947. ////                alert(newExpenseModalSystem.soData[value].sales_project_asset_head_id )
  948. //                if(newExpenseModalSystem.soData[value].sales_project_asset_head_id !=null && newExpenseModalSystem.soData[value].sales_project_asset_head_id !='') {
  949. ////                    alert('here')
  950. //                    populateAndSetSelectByAjaxSelector(newExpenseModalSystem.toBeBalancedFromSelector, [newExpenseModalSystem.soData[value].sales_project_asset_head_id])
  951. //                }
  952. //                else if(newExpenseModalSystem.soData[value].internal_project_asset_head_id !=null && newExpenseModalSystem.soData[value].internal_project_asset_head_id !='')
  953. //                    populateAndSetSelectByAjaxSelector(newExpenseModalSystem.toBeBalancedFromSelector, [newExpenseModalSystem.soData[value].internal_project_asset_head_id]);
  954.             }
  955.         })[0].selectize;
  956.         newExpenseModalSystem.leadSelector = $('#newExpenseModal .leadIdExp').selectize({
  957.             placeholder: 'Choose a Lead/Bid/tender',
  958.             multiple: false,
  959. //            options: APTL.productListArray,
  960.             options: [],
  961.             valueField: 'value',
  962.             labelField: 'text',
  963.             preload: 'focus',
  964.             searchField: ['text', 'value'],
  965.             load: function (query, callback) {
  966. //                        if (!query.length) return // callback();
  967.                 if (!query.length) query = '_EMPTY_';
  968.                 var pika_ind_id = $($(this)[0].$input["0"]).attr('data-id')
  969.                 $.ajax({
  970.                     url: BaseURL + "select_data_ajax",
  971.                     type: 'POST',
  972.                     dataType: 'json',
  973.                     data: {
  974.                         //returnJson: 1,
  975.                         //sessionData: sessionData
  976.                         query: query,
  977.                         tableName: "sales_lead",
  978.                         valueField: "lead_id",
  979.                         textField: "rendered_text",
  980.                         entity_group: 0,
  981.                         selectorId: $($(this)[0].$input["0"]).attr('id'),
  982.                         isMultiple: 0,
  983.                         dataId: pika_ind_id,
  984. //                        isMultiple: 0,
  985.                         //textField: "rendered_text",
  986. //
  987.                         renderTextFormat: "#__value__ __document_hash__ - Bid: __bid_number__",
  988.                         andConditions: [],
  989.                         andOrConditions: [
  990.                             {type: "=", field: "approved", value: 1},
  991.                         ],
  992.                         mustConditions: [
  993.                             {type: "=", field: "approved", value: 1},
  994.                         ],
  995.                         joinTableData: [
  996.                             //
  997.                             // {
  998.                             //     tableName: "project",
  999.                             //     joinFieldPrimary: "project_id",
  1000.                             //     joinOn: 'project_id',
  1001.                             //     tableJoinType: 'left join',
  1002.                             //     // fieldJoinType: '=',
  1003.                             //     // selectPrefix: '',
  1004.                             //     selectFieldList: [
  1005.                             //         'project_name', 'sales_project_asset_head_id', 'internal_project_asset_head_id'
  1006.                             //
  1007.                             //     ]
  1008.                             // },
  1009.                             //
  1010.                             // {
  1011.                             //     tableName: "acc_clients",
  1012.                             //     joinFieldPrimary: "client_id",
  1013.                             //     joinOn: 'client_id',
  1014.                             //     tableJoinType: 'join',
  1015.                             //     // fieldJoinType: '=',
  1016.                             //     // selectPrefix: 'client_',
  1017.                             //     selectFieldList: [
  1018.                             //         'client_name'
  1019.                             //
  1020.                             //     ]
  1021.                             // },
  1022.                         ],
  1023.                         convertToObject: [
  1024. //                            'accessories', 'issues'
  1025.                         ],
  1026.                         skipDefaultCompanyId: 1,
  1027.                         itemLimit: '_ALL_'
  1028.                         // setDataForSingle: 1,
  1029.                     },
  1030.                     error: function () {
  1031.                         // callback();
  1032.                     },
  1033.                     success: function (res) {
  1034.                         newExpenseModalSystem.leadData = res.dataById
  1035.                         callback(res.data);
  1036.                         if (res.setValueArray.length != 0 && res.selectorId != '') {
  1037.                             if (res.isMultiple == 1)
  1038.                                 $('#' + res.selectorId).selectize()[0].selectize.setValue(res.setValueArray)
  1039.                             else
  1040.                                 $('#' + res.selectorId).selectize()[0].selectize.setValue(res.setValue)
  1041.                         }
  1042. //                        alert('pika master')
  1043.                     }
  1044.                 });
  1045.             },
  1046.             onChange: function (value) {
  1047. //                alert(value )
  1048. //                newExpenseModalSystem.toBeBalancedFromSelector.setValue('')
  1049. //                if(!value.length)return;
  1050. ////                alert(newExpenseModalSystem.soData[value].sales_project_asset_head_id )
  1051. //                if(newExpenseModalSystem.soData[value].sales_project_asset_head_id !=null && newExpenseModalSystem.soData[value].sales_project_asset_head_id !='') {
  1052. ////                    alert('here')
  1053. //                    populateAndSetSelectByAjaxSelector(newExpenseModalSystem.toBeBalancedFromSelector, [newExpenseModalSystem.soData[value].sales_project_asset_head_id])
  1054. //                }
  1055. //                else if(newExpenseModalSystem.soData[value].internal_project_asset_head_id !=null && newExpenseModalSystem.soData[value].internal_project_asset_head_id !='')
  1056. //                    populateAndSetSelectByAjaxSelector(newExpenseModalSystem.toBeBalancedFromSelector, [newExpenseModalSystem.soData[value].internal_project_asset_head_id]);
  1057.             }
  1058.         })[0].selectize;
  1059.         newExpenseModalSystem.modalMode = typeof expenseModalMode !== 'undefined' ? expenseModalMode : 'standalone';
  1060.         newExpenseModalSystem.poSelector = $('#newExpenseModal .poIdExp').selectize({
  1061.             placeholder: 'Choose an Order',
  1062.             multiple: false,
  1063. //            options: APTL.productListArray,
  1064.             options: [],
  1065.             valueField: 'value',
  1066.             labelField: 'text',
  1067.             preload: 'focus',
  1068.             searchField: ['text', 'value', 'lc_number', 'supplier_name'],
  1069.             load: function (query, callback) {
  1070. //                        if (!query.length) return // callback();
  1071.                 if (!query.length) query = '_EMPTY_';
  1072.                 var pika_ind_id = $($(this)[0].$input["0"]).attr('data-id')
  1073.                 $.ajax({
  1074.                     url: BaseURL + "select_data_ajax",
  1075.                     type: 'POST',
  1076.                     dataType: 'json',
  1077.                     // render: {
  1078.                     //     option: function (item, escape) {
  1079.                     //         return '<div class="p-l-10 p-r-10">'
  1080.                     //             + '<h6> #'+escape(item[value])+' ' + escape(item[document_hash]) + ' -- '+ escape(item[lc_number])+'</h6> '
  1081.                     //             + '<span>Supplier:' + escape(item[supplier_name]) + '</span> '
  1082.                     //             //+ '<span>Name:'+item.name+'</span> '
  1083.                     //             //+ '<span>DEBUG:'+item.score+'</span>'
  1084.                     //             + '</div>';
  1085.                     //     }
  1086.                     // },
  1087.                     data: {
  1088.                         //returnJson: 1,
  1089.                         //sessionData: sessionData
  1090.                         query: query,
  1091.                         tableName: "purchase_order",
  1092.                         valueField: "purchase_order_id",
  1093.                         textField: "rendered_text",
  1094.                         entity_group: 0,
  1095.                         selectorId: $($(this)[0].$input["0"]).attr('id'),
  1096.                         isMultiple: 0,
  1097.                         dataId: pika_ind_id,
  1098. //
  1099.                         renderTextFormat: "#__value__ __document_hash__ ( __supplier_name__ ) -- __lc_number__",
  1100.                         andConditions: [],
  1101.                         andOrConditions: [
  1102.                             // {type: "=", field: "supplier_id", value: isNaN(query) ? '' : query},
  1103.                             {type: "=", field: "purchase_order_id", value: isNaN(query) ? '' : query},
  1104.                             {type: "like", field: "document_hash", value: query},
  1105.                             {type: "like", field: "acc_suppliers_0.supplier_name", value: query},
  1106.                             {type: "like", field: "lc_number", value: query},
  1107.                         ],
  1108.                         mustConditions: [
  1109.                             {type: "=", field: "approved", value: 1},
  1110.                         ],
  1111.                         joinTableData: [
  1112.                             {
  1113.                                 tableName: "acc_suppliers",
  1114.                                 joinFieldPrimary: "supplier_id",
  1115.                                 joinOn: 'supplier_id',
  1116.                                 tableJoinType: 'left join',
  1117.                                 // fieldJoinType: '=',
  1118.                                 // selectPrefix: 'supplier_',
  1119.                                 selectFieldList: [
  1120.                                     'supplier_name'
  1121.                                 ]
  1122.                             },
  1123.                         ],
  1124.                         convertToObject: [
  1125. //                            'accessories', 'issues'
  1126.                         ],
  1127.                         skipDefaultCompanyId: 1
  1128.                         // setDataForSingle: 1,
  1129.                     },
  1130.                     error: function () {
  1131.                         // callback();
  1132.                     },
  1133.                     success: function (res) {
  1134.                         callback(res.data);
  1135.                         if (res.setValueArray.length != 0 && res.selectorId != '') {
  1136.                             if (res.isMultiple == 1)
  1137.                                 $('#' + res.selectorId).selectize()[0].selectize.setValue(res.setValueArray)
  1138.                             else
  1139.                                 $('#' + res.selectorId).selectize()[0].selectize.setValue(res.setValue)
  1140.                         }
  1141. //                        alert('pika master')
  1142.                     }
  1143.                 });
  1144.             },
  1145.             onChange: function (value) {
  1146.                 newExpenseModalSystem.refreshDistributedProductListForExpenseBalancing()
  1147.             }
  1148.         })[0].selectize;
  1149.         newExpenseModalSystem.headSelector = $('#newExpenseModal #expenseModalExpenseId').selectize({})[0].selectize;
  1150.         $(document).on('change', '#exp_check_expense_distribution_on_product', function () {
  1151.             newExpenseModalSystem.refreshDistributedProductListForExpenseBalancing();
  1152.         });
  1153.         $(document).on('change', '.exp_distribution_percentage', function () {
  1154.             var this_data_id = $(this).data('id');
  1155.             if ($(this).val() == '') $(this).val(0)
  1156.             if ($('#expense_amount').val() == '') $('#expense_amount').val(0)
  1157.             $('.exp_distribution_amount' + this_data_id).val(($('#expense_amount').val() * $(this).val() / 100).toFixed(2));
  1158.             newExpenseModalSystem.distributedProductAmountTotalRecalculate();
  1159.         })
  1160.         $(document).on('change', '.exp_distribution_amount', function () {
  1161.             var this_data_id = $(this).data('id');
  1162.             if ($(this).val() == '') $(this).val(0)
  1163.             if ($('#expense_amount').val() == '') $('#expense_amount').val(0)
  1164.             if ($('#expense_amount').val() != 0)
  1165.                 $('.exp_distribution_percentage' + this_data_id).val((($(this).val() * 100) / ($('#expense_amount').val())).toFixed(2));
  1166.             else
  1167.                 $('.exp_distribution_percentage' + this_data_id).val((0).toFixed(2));
  1168.             newExpenseModalSystem.distributedProductAmountTotalRecalculate(1);
  1169.         })
  1170.         if (canSelectAnyHeadForExpenseBalancing == 1) {
  1171.             newExpenseModalSystem.toBeBalancedFromSelector = update_head_selectors('#newExpenseModal .expenseToBePaidTo', {
  1172.                 markerHash: newExpenseModalSystem.toBeBalancedFromSelectorFilterGenerator(),
  1173.                 // markerHash: '_AEMP_',
  1174.                 // renderText: '#__value__ - __name__ ',
  1175.                 // markerHashStrictMatch: 1
  1176.             }, 1);
  1177.         } else {
  1178.             newExpenseModalSystem.toBeBalancedFromSelector = $('#newExpenseModal .expenseToBePaidTo').selectize({
  1179.                 placeholder: 'Choose a Head',
  1180.                 multiple: false,
  1181. //            options: APTL.productListArray,
  1182.                 options: [
  1183.                     {
  1184.                         value: -1,
  1185.                         text: 'My General Head',
  1186.                     },
  1187.                     {
  1188.                         value: -2,
  1189.                         text: 'My Advance',
  1190.                     }
  1191.                 ],
  1192.                 valueField: 'value',
  1193.                 labelField: 'text',
  1194.                 preload: 'focus',
  1195.                 searchField: ['text', 'value'],
  1196.                 onChange: function (value) {
  1197.                 }
  1198.             })[0].selectize;
  1199.             newExpenseModalSystem.toBeBalancedFromSelector.setValue(-2)
  1200.         }
  1201.         newExpenseModalSystem.checkSelector = $('#newExpenseModal #expense_check_id').selectize({
  1202.             placeholder: 'Choose a Cheque',
  1203.             multiple: false,
  1204. //            options: APTL.productListArray,
  1205.             options: [],
  1206.             valueField: 'value',
  1207.             labelField: 'text',
  1208.             preload: 'focus',
  1209.             searchField: ['text', 'value'],
  1210.             load: function (query, callback) {
  1211. //                        if (!query.length) return // callback();
  1212.                 if (!query.length) query = '_EMPTY_';
  1213.                 var pika_ind_id = $($(this)[0].$input["0"]).attr('data-id')
  1214.                 $.ajax({
  1215.                     url: BaseURL + "select_data_ajax",
  1216.                     type: 'POST',
  1217.                     dataType: 'json',
  1218.                     data: {
  1219.                         //returnJson: 1,
  1220.                         //sessionData: sessionData
  1221.                         query: query,
  1222.                         tableName: "acc_check",
  1223.                         valueField: "check_id",
  1224.                         // textField: "check_number",
  1225.                         entity_group: 0,
  1226.                         selectorId: $($(this)[0].$input["0"]).attr('id'),
  1227.                         isMultiple: 0,
  1228.                         dataId: pika_ind_id,
  1229. //                        isMultiple: 0,
  1230.                         textField: "rendered_text",
  1231. //
  1232.                         renderTextFormat: "__acc_number__ -- __check_number__ ",
  1233.                         andConditions: [],
  1234.                         andOrConditions: [
  1235.                             // {type: "=", field: "accounts_head_id", value: },
  1236.                             {type: "like", field: "check_number", value: query},
  1237.                             {type: "like", field: "acc_number", value: query},
  1238.                         ],
  1239.                         mustConditions: [
  1240.                             {type: "!=", field: "assigned", value: 1},
  1241.                             {
  1242.                                 type: "in",
  1243.                                 field: "accounts_head_id",
  1244.                                 value: [($('#expenseModalPayFrom').val() == '' ? 0 : $('#expenseModalPayFrom').val()), ($('#expenseModalToBePaidTo').val() == '' ? 0 : $('#expenseModalToBePaidTo').val())]
  1245.                             },
  1246.                             // {type: "not_in", field: "accounts_head_id", value: [0,'null']},
  1247.                         ],
  1248.                         orderByConditions: [  //sequential
  1249.                             {
  1250.                                 field: 'check_id',
  1251.                                 // fieldValues: [5,6,9],
  1252.                                 sortType: 'ASC'
  1253.                             }
  1254.                         ],
  1255.                         joinTableData: [
  1256.                             {
  1257.                                 tableName: "acc_accounts_head",
  1258.                                 joinFieldPrimary: "accounts_head_id",
  1259.                                 joinOn: 'accounts_head_id',
  1260.                                 tableJoinType: 'left join',
  1261.                                 // fieldJoinType: '=',
  1262.                                 selectPrefix: 'check_head_',
  1263.                                 selectFieldList: [
  1264.                                     'name', 'accounts_head_id'
  1265.                                 ]
  1266.                             },
  1267.                         ],
  1268.                         convertToObject: [
  1269. //                            'accessories', 'issues'
  1270.                         ],
  1271.                         skipDefaultCompanyId: 1
  1272.                         // setDataForSingle: 1,
  1273.                     },
  1274.                     error: function () {
  1275.                         // callback();
  1276.                     },
  1277.                     success: function (res) {
  1278.                         newExpenseModalSystem.checkData = res.dataById
  1279.                         callback(res.data);
  1280.                         if (res.setValueArray.length != 0 && res.selectorId != '') {
  1281.                             if (res.isMultiple == 1)
  1282.                                 $('#' + res.selectorId).selectize()[0].selectize.setValue(res.setValueArray)
  1283.                             else
  1284.                                 $('#' + res.selectorId).selectize()[0].selectize.setValue(res.setValue)
  1285.                         } else if (res.data.length > 0) {
  1286.                             $('#' + res.selectorId).selectize()[0].selectize.setValue(res.data[0].value)
  1287.                         }
  1288. //                        alert('pika master')
  1289.                     }
  1290.                 });
  1291.             },
  1292.             onChange: function (value) {
  1293.                 if (!value.length) {
  1294.                     $('#expense_check_number_here').val('');
  1295.                     // $('#expense_check_id').val('');
  1296.                     $('.expense_check_number_div').hide();
  1297.                 }
  1298.                 $('#expense_check_number_here').val(newExpenseModalSystem.checkData[value].check_number);
  1299.                 $('.expense_check_number_div').show();
  1300.             }
  1301.         })[0].selectize;
  1302.         if (newExpenseModalSystem.modalMode == 'standalone') {
  1303.             $('.expense_change_check_number').change(function () {
  1304.                 populateAndSetSelectByAjaxSelector(newExpenseModalSystem.checkSelector, '_ALL_')
  1305.             })
  1306.             var expenseOptions = {
  1307.                 beforeSubmit: function (arr, $form, options) {
  1308.                     $('.expenseForm').prepend(' <div class="form_ongoing_submit"></div>');
  1309.                 },
  1310.                 success: showResponsExpense // post-submit callback
  1311.             };
  1312.             function showResponsExpense(responseText, statusText, xhr, $form) {
  1313.                 if (statusText == 'success') {
  1314.                     if (responseText.success == true) {
  1315.                         alertify.alert('Successfully Added The Expense. Document Name: ' + responseText.docHash);
  1316.                         alertify.success("Expense Added");
  1317.                     } else {
  1318.                         alertify.alert('Action Failed');
  1319.                         alertify.error("Could not Add the Expense");
  1320.                         addCreateConfirmed = 0;
  1321.                     }
  1322.                 } else {
  1323.                     alertify.alert('No response from server');
  1324.                     alertify.error("Could not Add the Expense");
  1325.                     addCreateConfirmed = 0;
  1326.                 }
  1327.                 $('.expenseForm .form_ongoing_submit').remove();
  1328. //                    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
  1329. //                            '\n\nThe output div should have already been updated with the responseText.');
  1330. //                    //    console.log('status: ' + statusText + '\n\nresponseText: \n' + responseText +
  1331. //                            '\n\nThe output div should have already been updated with the responseText.');
  1332.             }
  1333.             $('.expenseForm').ajaxForm(expenseOptions);
  1334.             $('.expenseModalSubmit').click(function (e) {
  1335.                 e.preventDefault();
  1336.                 if (!$('.expenseForm .form_ongoing_submit').length) {
  1337.                     $('.expenseForm').submit()
  1338.                 }
  1339.             });
  1340.         } else {
  1341.             $('.expenseModalSubmit').click(function (e) {
  1342.                 e.preventDefault();
  1343.                 newExpenseModalSystem.checkAndAddExpenseDataToList();
  1344.             });
  1345.         }
  1346.         $(document).on('click', '.triggerEditExpenseModal', function (e) {
  1347.             e.preventDefault();
  1348.             var this_data_row_id = $(this).data('rowId')
  1349.             var dataRow = {}
  1350.             newExpenseModalSystem.triggerExpenseModal(dataRow);
  1351.         });
  1352.         $('.filter').hide();
  1353.         $('.filter-default').show();
  1354.         $('.filter_by_this').change(function () { //            alert('here')
  1355.             var filter_ind = $(this).val()
  1356.             $('.filter').hide();
  1357.             $('.filter-' + filter_ind).show();
  1358.         })
  1359.         $('.exp_att_file').change(function () {
  1360.             // triggerOcr('#'+$(this).attr('id'))
  1361.             if (BUDDYBEE_COIN_BALANCE >= 1)
  1362.                 initiateOcr($(this).attr('id'))
  1363.         });
  1364.     });
  1365. </script>