<style type="text/css">
    .extra-mar-botm{margin-bottom: 5px !important;}
</style>
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2><?= print_lang($app_lang,'add_new_account'); ?></h2>
        <ol class="breadcrumb">
            <li>
                <a class="url-elem" href="<?php echo url('/dashboard'); ?>"><?= print_lang($app_lang,'home'); ?></a>
            </li>
            <li>
                <a class="url-elem" href="<?php echo url('/accounts'); ?>"><?= print_lang($app_lang,'accounts'); ?></a>
            </li>
            <li class="active">
                <strong><?= print_lang($app_lang,'add_new_account'); ?></strong>
            </li>
        </ol>
    </div>
    <div class="col-lg-2">
    </div>
</div>


<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox-title">
        <h5><?= print_lang($app_lang,'fields_with'); ?> <strong class="text-danger">*</strong> <?= print_lang($app_lang,'are_mandatory'); ?></h5>
    </div>
    <div class="ibox-content">
        <!-- spinner -->
        <div class="sk-spinner sk-spinner-three-bounce">
            <div class="sk-bounce1"></div>
            <div class="sk-bounce2"></div>
            <div class="sk-bounce3"></div>
        </div>
        <!-- spinner -->
        <div class="row">
            <div class="col-sm-12 b-r">
                <form role="form" id="accounts-form" action="<?php echo url('/accounts/update').'/'.$editing_data['uid']; ?>">

                    <div class="row extra-mar-botm">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'name'); ?> <strong class="text-danger">*</strong></label>
                                <input type="text" class="form-control" name="name" value="<?= $editing_data['name']; ?>" placeholder="<?= print_lang($app_lang,'name'); ?>">
                            </div>
                        </div>
                        <?php
                        $display_none = 'display-none';
                        if($editing_data['type'] == 'client')
                        {
                            $display_none = '';
                        }

                        if($editing_data['type'] == 'cashbook')
                        {
                            $display_none = '';
                        }

                        ?>
                        <div class="col-md-6">
                            <div class="form-group <?php if(strpos($editing_data['uid'],"SAFEACCOUNT") !== FALSE OR strpos($editing_data['uid'],"CASHSALE") !== FALSE){ echo 'pointer-none'; } ?>">
                                <label><?= print_lang($app_lang,'under_ac'); ?> <strong class="text-danger">*</strong></label>
                                <select class="chosen-select form-control" name="type">
                                    <option selected="" value="">Root</option>
                                    <?php foreach($root_accounts as $row){ ?>
                                        <option value="<?= $row['uid']; ?>" <?php if($editing_data['type'] == $row['uid']){ echo 'selected="selected"'; } ?>><?= ($row['branch'] == 'general') ? print_lang($app_lang,'builtin_account_'.$row['uid']) : $row['name']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="shared-account-row <?php echo $display_none; ?>">
                        <div class="row extra-mar-botm">
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label><?= print_lang($app_lang,'shared'); ?></label>
                                    <div style="margin-top: 10px;">
                                        <label class="checkbox-inline i-checks">
                                            <input type="radio" name="shared" value="yes" id="shared_yes" <?php if($editing_data['shared'] == 'yes'){echo "checked";}?>> &nbsp;&nbsp;&nbsp; <?= print_lang($app_lang,'shared_yes'); ?>
                                        </label>
                                        <label class="checkbox-inline i-checks" style="margin-left: 30px;">
                                            <input type="radio" name="shared" value="no" id="shared_no" <?php if($editing_data['shared'] == 'no'){echo "checked";}?>> &nbsp;&nbsp;&nbsp; <?= print_lang($app_lang,'shared_no'); ?>
                                        </label>
                                    </div>
                                </div>
                            </div>

                            <div class="col-md-3 customer-user-col-data <?php if($editing_data['type'] != 'client'){echo 'display-none';}?>">
                                <div class="form-group">
                                    <label><?= print_lang($app_lang,'is_user'); ?></label>
                                    <div style="margin-top: 10px;">
                                        <label class="checkbox-inline i-checks">
                                            <input type="radio" name="is_user" value="yes" id="is_user_yes" <?php if($editing_data['is_user'] == 'yes'){echo "checked";}?>> &nbsp;&nbsp;&nbsp; <?= print_lang($app_lang,'is_user_yes'); ?>
                                        </label>
                                        <label class="checkbox-inline i-checks" style="margin-left: 30px;">
                                            <input type="radio" name="is_user" value="no" id="is_user_no" <?php if($editing_data['is_user'] == 'no'){echo "checked";}?>> &nbsp;&nbsp;&nbsp; <?= print_lang($app_lang,'is_user_no'); ?>
                                        </label>
                                    </div>
                                </div>
                            </div>

                            <div class="col-md-3 customer-user-col-data <?php if($editing_data['type'] != 'client'){echo 'display-none';}?>">
                                <div class="form-group">
                                    <label><?= print_lang($app_lang,'account_username'); ?></label>
                                    <input type="text" class="form-control" <?php if($editing_data['is_user'] == 'no'){echo "readonly";}?> value="<?= $editing_data['username']; ?>" name="username" placeholder="<?= print_lang($app_lang,'account_username'); ?>">
                                </div>
                            </div>

                            <div class="col-md-3 customer-user-col-data <?php if($editing_data['type'] != 'client'){echo 'display-none';}?>">
                                <div class="form-group">
                                    <label><?= print_lang($app_lang,'account_password'); ?></label>
                                    <input type="password" class="form-control" <?php if($editing_data['is_user'] == 'no'){echo "readonly";}?> name="update_password" placeholder="<?= print_lang($app_lang,'account_password'); ?>">
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- client type row -->
                    <div class="client-category-row-expand <?php if($editing_data['type'] != 'client'){ echo 'display-none'; } ?>">
                        <div class="row extra-mar-botm">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label><?= print_lang($app_lang,'client_account_type'); ?></label>
                                    <div style="margin-top: 10px;">
                                        <label class="checkbox-inline i-checks">
                                            <input type="radio" name="client_type" value="general" <?php if($editing_data['client_type'] == 'general'){ echo 'checked'; } ?>> &nbsp;&nbsp;&nbsp; <?= print_lang($app_lang,'client_account_radio_general'); ?>
                                        </label>

                                        <label class="checkbox-inline i-checks">
                                            <input type="radio" name="client_type" value="category" <?php if($editing_data['client_type'] == 'category'){ echo 'checked'; } ?>> &nbsp;&nbsp;&nbsp; <?= print_lang($app_lang,'client_account_radio_category'); ?>
                                        </label>

                                        <label class="checkbox-inline i-checks">
                                            <input type="radio" name="client_type" value="sales_man" <?php if($editing_data['client_type'] == 'sales_man'){ echo 'checked'; } ?>> &nbsp;&nbsp;&nbsp; <?= print_lang($app_lang,'client_account_radio_sales_man'); ?>
                                        </label>

                                        <label class="checkbox-inline i-checks">
                                            <input type="radio" name="client_type" value="marketer" <?php if($editing_data['client_type'] == 'marketer'){ echo 'checked'; } ?>> &nbsp;&nbsp;&nbsp; <?= print_lang($app_lang,'client_account_radio_marketer'); ?>
                                        </label>
                                    </div>
                                </div>
                            </div>

                            <div class="col-md-6">
                                <div class="client-categories-select <?php if($editing_data['client_type'] != 'category'){ echo 'display-none'; } ?>">
                                    <div class="form-group">
                                        <label><?= print_lang($app_lang,'client_dp_client_categories'); ?> <strong class="text-danger">*</strong></label>
                                        <select class="chosen-select form-control" name="category">
                                            <option selected="" value=""><?= '--'.print_lang($app_lang,'client_dp_client_categories').'--'; ?></option>
                                            <?php foreach($client_categories as $row){ ?>
                                                <option value="<?= $row['uid']; ?>" <?php if($editing_data['category'] == $row['uid']){ echo 'selected="selected"'; } ?>><?= $row['name']; ?></option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                </div>

                                <div class="client-sales-man-select <?php if($editing_data['client_type'] != 'sales_man'){ echo 'display-none'; } ?>">
                                    <div class="form-group">
                                        <label><?= print_lang($app_lang,'client_dp_sales_man'); ?> <strong class="text-danger">*</strong></label>
                                        <select class="chosen-select form-control" name="sales_man">
                                            <option selected="" value=""><?= '--'.print_lang($app_lang,'client_dp_sales_man').'--'; ?></option>
                                            <?php foreach($sales_man as $row){ ?>
                                                <option value="<?= $row['uid']; ?>" <?php if($editing_data['sales_man'] == $row['uid']){ echo 'selected="selected"'; } ?>><?= $row['name']." ".$row['last_name']; ?></option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                </div>

                                <div class="client-marketer-select <?php if($editing_data['client_type'] != 'marketer'){ echo 'display-none'; } ?>">
                                    <div class="form-group">
                                        <label><?= print_lang($app_lang,'client_dp_marketer'); ?> <strong class="text-danger">*</strong></label>
                                        <select class="chosen-select form-control" name="marketer">
                                            <option selected="" value=""><?= '--'.print_lang($app_lang,'client_dp_marketer').'--'; ?></option>
                                            <?php foreach($marketers as $row){ ?>
                                                <option value="<?= $row['uid']; ?>" <?php if($editing_data['marketer'] == $row['uid']){ echo 'selected="selected"'; } ?>><?= $row['name']." ".$row['last_name']; ?></option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- accounts-form-expended-makups -->
                    <div class="accounts-form-expended-makups <?php if($editing_data['type'] == 'root'){ echo 'display-none'; } ?>">
                        
                        <div class="row extra-mar-botm">
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label><?= print_lang($app_lang,'code'); ?></label>
                                    <input type="text" class="form-control" name="code" value="<?= $editing_data['code']; ?>" placeholder="<?= print_lang($app_lang,'code'); ?>">
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label><?= print_lang($app_lang,'mobile'); ?></label>
                                    <input type="text" class="form-control" name="mobile" value="<?= $editing_data['mobile']; ?>" placeholder="<?= print_lang($app_lang,'mobile'); ?>">
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label><?= print_lang($app_lang,'email'); ?></label>
                                    <input type="text" class="form-control" name="email" value="<?= $editing_data['email']; ?>" placeholder="<?= print_lang($app_lang,'email'); ?>">
                                </div>
                            </div>
                            <div class="col-md-3 text-right">
                                <a href="javascript:void(0);" id="opening-balance-add-trigger" data-lang-amount-iput="<?= print_lang($app_lang,'amount'); ?>" data-lang-debit-iput="<?= print_lang($app_lang,'account_opening_balance_debit'); ?>" data-lang-credit-iput="<?= print_lang($app_lang,'account_opening_balance_credit'); ?>" data-lang-currency-iput="<?= print_lang($app_lang,'account_opening_balance_currency'); ?>" style="margin-top: 28px;" class="btn btn-sm btn-outline btn-primary"><i class="fa fa-plus"></i>&nbsp; Add Opening Balance</a>
                            </div>
                        </div>

                        <?php
                        if(empty($editing_data['opening_balance']))
                        {
                            $opening_balances = array();
                        }
                        else
                        {
                            $opening_balances = json_decode($editing_data['opening_balance'],true);
                        }
                        ?>

                        <!-- account-opening-balance-wrap -->
                        <div id="account-opening-balance-wrap">
                            <?php $cnt = 0; foreach($opening_balances as $obrow){ $cnt++; ?>
                            <div class="row extra-mar-botm currency-row currency-snippet-row-<?= $cnt; ?>">
                                <div class="col-md-11">
                                    <div class="row">
                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label><?= print_lang($app_lang,'account_opening_balance_debit'); ?></label>
                                                <input type="text" class="form-control" name="ob_debit[]" value="<?= $obrow['ob_debit']; ?>" placeholder="<?= print_lang($app_lang,'amount'); ?>">
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label><?= print_lang($app_lang,'account_opening_balance_credit'); ?></label>
                                                <input type="text" class="form-control" name="ob_credit[]" value="<?= $obrow['ob_credit']; ?>" placeholder="<?= print_lang($app_lang,'amount'); ?>">
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label><?= print_lang($app_lang,'account_opening_balance_currency'); ?></label>
                                                <select class="chosen-select form-control" name="currency[]">
                                                    <option selected="" disabled="">-- <?= print_lang($app_lang,'account_opening_balance_currency'); ?> --</option>
                                                    <?php foreach($currencies as $row){ ?>
                                                        <option value="<?= $row['uid']; ?>" <?php if($obrow['currency'] == $row['uid']){ echo 'selected="selected"'; } ?>><?= $row['name']; ?></option>
                                                    <?php } ?>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-1 text-right">
                                    <a href="javascript:void(0);" style="margin-top: 25px;" class="btn btn-outline btn-danger del-opening-balance-row"><i class="fa fa-trash"></i></a>
                                </div>
                            </div>
                            <?php } ?>
                        </div>
                        <!-- account-opening-balance-wrap -->

                        <div class="row extra-mar-botm">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label><?= print_lang($app_lang,'memo'); ?> <strong class="text-danger">*</strong></label>
                                    <textarea class="form-control" name="memo" placeholder="<?= print_lang($app_lang,'memo'); ?>" rows="3"><?= $editing_data['memo']; ?></textarea>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label><?= print_lang($app_lang,'address'); ?> </label>
                                    <textarea class="form-control" name="address" placeholder="<?= print_lang($app_lang,'address'); ?>" rows="3"><?= $editing_data['address']; ?></textarea>
                                </div>
                            </div>
                        </div>

                    </div>
                    <!-- accounts-form-expended-makups -->

                    <div class="row extra-mar-botm">
                        <div class="col-md-12 text-right">
                            <a class="btn btn-w-m btn-outline btn-danger url-elem" href="<?php echo url('/accounts'); ?>"><?= print_lang($app_lang,'cancel'); ?></a>
                            <button class="btn btn-w-m btn-primary" type="submit"><?= print_lang($app_lang,'update'); ?></button>
                        </div>
                    </div>

                </form>
            </div>
        </div>
    </div>

</div>


<div class="display-none" id="currency-options-wrapper">
    <?php foreach($currencies as $row){ ?>
        <option value="<?= $row['uid']; ?>"><?= $row['name']; ?></option>
    <?php } ?>
</div>
