<?php
$path="../../";
include("../../map.php");
if($_GET["ne"]=="service"){
  $folder="services";
}elseif($_GET["ne"]=="muhasebe"){
  $folder="accounting";
}
?>
<form id="uekle" autocomplete="off" class="w1600 mw1600">
  <!--<button onclick="vtr('addtr')" type="button" style="float:right; margin-bottom:3px;"><i class="fa fa-plus"></i> Satır Ekle</button>-->
  <table class="table" style="" id="plist">
    <tr class="mdn">
      <th><?php echo $t46;?></th>
      <th class="w8 mw8" style="text-align:right;"><?php echo $sdil[88]; //Birim?></th>
      <th class="w5 mw5" style="text-align:right;"><?php echo $sdil[86]; //kdv?></th>
      <th class="w10 mw10" style="text-align:right;<?php if($_GET["islem"]<>"dservice"){echo "display:none;";}?>">Maliyet</th>
      <th class="w10 mw10" style="text-align:right;<?php if($_GET["islem"]<>"dservice"){echo "display:none;";}?>">Liste Fiyatı</th>
      <th class="w10 mw10" style="text-align:right;"><?php if($_GET["islem"]=="afatura"){echo $sdil[84];}else{echo $sdil[85];}?></th>
      <th class="w10 mw10" style="text-align:right;"><?php echo $sdil[144]; //Tutar?></th>
      <th class="w8 mw8"><?php echo $sdil[213]; //işlemler?></th>
    </tr>
    <tr class="addtr" style="" id="addtr" data-id="0" data-cke="0" data-action="../<?php echo $folder?>/ajax.php?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&durum=uekle" data-url="../public/products.php?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>" data-did="#products" data-ref_id="#show_total" data-ref_url="../accounting/accounting_calc.php?show_total=yes&id=<?php echo $_GET["id"]?>">
      <td class="" style="position:relative;">
        <div id="at1_name" style="display:none; position: absolute; right: 30px; top: 12px; width: 50%; overflow: hidden; height: 18px; text-align:right;"></div>
        <input type="text" list="Pt4" id="at1" name="t1" class="form-control" value="" placeholder="<?php echo $t46;?>"  autofocus autocomplete="off">
        <datalist ID="Pt4" style="display: none;"></datalist>
        <select name="rb" data-placeholder="<?php echo $sdil[221]; //Varyasyon Seçiniz?>" style="display:none;" class="form-control chosen-select w30 fl ml10" tabindex="8" id="var_select">
          <option value=""><?php echo $sdil[133]; //Varyasyon?></option>
        </select>
      </td>
      <td class="">
		<div class="input-group">
		<input type="number" class="form-control tar mtal" style="text-align:right; border:1px solid #ced4da73 !important" value="1" onfocus="if(this.value == '1') { this.value = ''} " onblur="if(this.value == '') { this.value='1'; }" name="s5" id="as5">
		  <span class="input-group-addon" id="basic-addon1" style="padding: 5px;">
		  <select size=1 name="t10" id="at10" class="sfa sna" style="font-size: 9px; padding: 3px; border:0px !important;">
			<?php if(!empty($t28)){$sbirim = explode(',',$t28); foreach($sbirim as $sbrm) {$s++; if($s > 20) {$s = 1;}?>
			  <option value="<?php echo $sbrm;?>"><?php echo $sbrm;?></option>
			<?php }}?>
			</select>
		  </span>
		</div>
    </td>
    <td class="">
      <input type="text" class="form-control" style=" border:0px; text-align:right;" value="<?php echo $module["s12"]?>" onfocus="if(this.value == '<?php echo $module["s12"]?>') { this.value = ''} " onblur="if(this.value == '') { this.value='<?php echo $module["s12"]?>'; }" id="as4" name="s4">
    </td>
    <td class="p0 mp0" style="<?php if($_GET["islem"]<>"dservice"){echo "display:none;";}?>">
      <div class="input-group">
        <input type="text" name="fumaliyet" id="amaliyet" class="form-control " style="border: 1px solid #ccc !important; text-align:right;" value="0.00" onfocus="if(this.value == '0.00') { this.value = ''} " onblur="if(this.value == '') { this.value='0.00'; }">
        <span class="input-group-addon" id="basic-addon1" style="padding: 5px;">
          <select class="sfa sna" name="t6" id="at6" style="font-size: 16px; padding: 3px; border:0px !important;">
            <option value="TRY" <?php if($kpb=="TRY"){echo "selected";}?>>&#xf195;</option>
            <option value="EUR" <?php if($kpb=="EUR"){echo "selected";}?>>&#xf153;</option>
            <option value="USD" <?php if($kpb=="USD"){echo "selected";}?>>&#xf155;</option>
            <option value="GBP" <?php if($kpb=="GBP"){echo "selected";}?>>&#xf154;</option>
          </select>
        </span>
      </div>
    </td>
    <td class="" style="<?php if($_GET["islem"]<>"dservice"){echo "display:none;";}?>">
      <input type="text" name="fulfiyat" id="alprice" class="form-control " style="border:0px; text-align:right;<?php if($rsfu["pb3"]<>0){echo "text-decoration: line-through;";}?>" value="0.00 " onfocus="if(this.value == '0.00') { this.value = ''} " onblur="if(this.value == '') { this.value='0.00'; }">
    </td>
    <td class="p0 mp0">
      <div class="input-group">
        <input type="text" name="price" class="form-control " style="border: 1px solid #ccc !important; text-align:right;" value="0.00" onfocus="if(this.value == '0.00 <?php echo $kpb?>') { this.value = ''} " onblur="if(this.value == '') { this.value='0.00'; }" id="aprice"  aria-describedby="basic-addon1">
        <span class="input-group-addon" id="basic-addon1" style="padding: 5px;">
          <select name="t2" class="sfa sna" style="font-size: 16px; padding: 3px; border:0px !important;">
            <option value="TRY" <?php if($kpb=="TRY"){echo "selected";}?>>&#xf195;</option>
            <option value="EUR" <?php if($kpb=="EUR"){echo "selected";}?>>&#xf153;</option>
            <option value="USD" <?php if($kpb=="USD"){echo "selected";}?>>&#xf155;</option>
            <option value="GBP" <?php if($kpb=="GBP"){echo "selected";}?>>&#xf154;</option>
          </select>
        </span>
      </div>
    </td>
    <td class="">
      <input type="text" name="y6" id="atotal" class="form-control" style="border:0px; text-align:right;" value="0.00">
    </td>
    <td class="">
      <div class="input-group-btn">
        <button class="btn btn-primary btn-update-row" type="button"><i class="fa fa-plus"></i></button>
        <!--<button class="btn btn-primary" type="button" style="margin-left:2px;"><i class="fa fa-search"></i></button>-->
      </div>
    </td>
  </tr>
  <tr id="xaddtr" style="display:none;padding: 0px;">
    <td colspan="<?php if($_GET["islem"]<>"dservice"){echo "6";}else{echo "8";}?>">
      <input type="checkbox" name="s3" value="1" class="fl mr5 mt5 mdn" title="<?php echo ctranslate("Konsinye")?>">
      <div><textarea class="form-control w97 fl" name="fun2" id="an2" style="height:34px;" placeholder="<?php echo ctranslate("Açıklama")?>"><?php echo $rsfu["n2"]?></textarea></div>
      <div id="xaddtd"></div>
    </td>
  </tr>
</table>
</form>
<script type='text/javascript'>
  jQuery(function() {
    jQuery("#at1").keyup(function(){
      var q = jQuery("#at1").val();
      jQuery('#Pt4').load('../public/datalist.php?ne=kayit&val=t4&q='+q+'');
    });
    jQuery("#var_select").change(function(){
      var price = jQuery('option:selected', this).data('price');
      var id = jQuery('option:selected', this).data('id');
      jQuery( "#as5" ).prop( "disabled", false ); jQuery("#as5").val('1');
      jQuery( "#aprice" ).prop( "disabled", false ); jQuery("#aprice").val(price);
      jQuery( "#atotal" ).prop( "disabled", false ); jQuery("#atotal").val(price);
      jQuery("#an2").val(desc);
    });
    jQuery("#addtr").click(function(){
      vtr('xaddtr');
    });
    jQuery("#at1").change(function(){
      var val = jQuery('#at1').val();
      var price = jQuery('#Pt4 option').filter(function() { return this.value == val; }).data('price');
      var pb = jQuery('#Pt4 option').filter(function() { return this.value == val; }).data('pb');
      var unit = jQuery('#Pt4 option').filter(function() { return this.value == val; }).data('unit');
      var lprice = jQuery('#Pt4 option').filter(function() { return this.value == val; }).data('lprice');
      var mprice = jQuery('#Pt4 option').filter(function() { return this.value == val; }).data('mprice');
      var tax = jQuery('#Pt4 option').filter(function() { return this.value == val; }).data('tax');
      var id = jQuery('#Pt4 option').filter(function() { return this.value == val; }).data('id');
      var attrvar = jQuery('#Pt4 option').filter(function() { return this.value == val; }).data('var');
      var title = jQuery('#Pt4 option').filter(function() { return this.value == val; }).data('title');
      var desc = jQuery('#Pt4 option').filter(function() { return this.value == val; }).data('desc');
      if(attrvar=="1"){
        show('var_select');
        jQuery('#var_select').load('../public/products_var.php?id=' + id);
      };
      if(price !== undefined){
        jQuery('#at1_name').show(); jQuery('#at1_name').html(title);
        jQuery('#xaddtd').load('../services/attr.php?uid=' + id);
        jQuery( "#as5" ).prop( "disabled", false ); jQuery("#as5").val('1');
        jQuery( "#as4" ).prop( "disabled", false ); jQuery("#as4").val(tax);
        jQuery( "#aprice" ).prop( "disabled", false ); jQuery("#aprice").val(price);
        jQuery( "#alprice" ).prop( "disabled", false ); jQuery("#alprice").val(lprice);
        jQuery( "#amaliyet" ).prop( "disabled", false ); jQuery("#amaliyet").val(mprice);
        jQuery( "#atotal" ).prop( "disabled", false ); jQuery("#atotal").val(price);
        //jQuery( "#at6" ).prop( "disabled", false ); jQuery("#at6").val(pb);
        jQuery( "#at10" ).prop( "disabled", false ); jQuery("#at10").val(unit);
        jQuery("#an2").val(desc);
      }else{
        jQuery( "#as5" ).prop( "disabled", false ); jQuery("#as5").val('1');
        jQuery( "#as4" ).prop( "disabled", false ); jQuery("#as4").val('<?php echo $module["s12"]?>');
        jQuery( "#aprice" ).prop( "disabled", false ); jQuery("#aprice").val('0');
        jQuery( "#atotal" ).prop( "disabled", false ); jQuery("#atotal").val('0');
        jQuery("#an2").val(desc);
      }
    });
    jQuery("#as5, #aprice").keyup(function(){
      var s5 = jQuery('#as5').val();
      var price = jQuery('#aprice').val();
      jQuery("#atotal").val(price*s5);
    });
    jQuery("#maliyet").keyup(function(){
      var price = jQuery('#maliyet').val();
      jQuery("#aprice").val(price);
    });
  });
</script>
<?php
$sqlf=mysqli_query($conn, "select * from t4 where ne='furun' and s1=".$_GET["id"]." order by id desc");
if(mysqli_num_rows($sqlf)>0 and $_GET["ne"]=="muhasebe"){
  echo "
  <script>
	jQuery(document).ready(function() {
		show('sts_bar');
		jQuery('#delbtn').prop('disabled', true);
		jQuery('#sts_txt').html('".ctranslate("Ürün Olan Fatura Silinemez")."');
    });
    </script>
    ";
  }elseif(mysqli_num_rows($sqlf)==0 and $_GET["ne"]=="muhasebe"){
    echo "
    <script>
    jQuery(document).ready(function() {
      show('sts_bar');
      jQuery('#delbtn').prop('disabled', false);
      jQuery('#sts_txt').html('".ctranslate("Lütfen Ürün Ekleyiniz")."');
      });
      </script>
      ";
    }
    while($rsfu=mysqli_fetch_assoc($sqlf)){
      $sqlu=mysqli_query($conn, "select * from ".$_SESSION["lang"]." where id=".$rsfu["s2"]." order by id desc"); $rsu=mysqli_fetch_assoc($sqlu);
      $jsi = json_decode($rsu["n17"], true);
      if(mysqli_num_rows($sqlu)>0){
        $uAdi=$rsu["t1"];
        $id=$rsu["id"]; include("../../../deppo/tools/script/prices.php");
      }else{
        $uAdi=$rsfu["n1"];
        $id="0";
      }
      ?>
      <script type='text/javascript'>
        jQuery(function() {
          jQuery("#maliyet<?php echo $rsfu["id"]?>").keyup(function(){
            var maliyet<?php echo $rsfu["id"]?> = jQuery('#maliyet<?php echo $rsfu["id"]?>').val();
            var fiyat<?php echo $rsfu["id"]?> = jQuery('#fiyat<?php echo $rsfu["id"]?>').val();
            if(maliyet<?php echo $rsfu["id"]?>>fiyat<?php echo $rsfu["id"]?>){
              jQuery("#fiyat<?php echo $rsfu["id"]?>").val(maliyet<?php echo $rsfu["id"]?>);
            }
          });
        });
      </script>
      <form action="../<?php echo $folder?>/ajax.php?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&durum=uguncelle&uid=<?php echo $rsfu["id"]?>" name="aform" id="PUpdate<?php echo $rsfu["id"]?>" autocomplete="off" class="w1600 mw1600">
        <table class="table" style="">
          <input type="hidden" name="urunid" value="<?php echo $id?>">
          <input type="hidden" name="fiyat" value="<?php echo wprice($fiyat1)?>">
          <tr class="uptr" id="<?php echo $rsfu["id"]?>tr" data-id="<?php echo $rsfu["id"];?>" data-cke="0" data-href="../public/products.php?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>" data-action="../<?php echo $folder?>/ajax.php?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&uid=<?php echo $rsfu["id"]?>&urunid=<?php echo $rsu["id"]?>&durum=uguncelle" data-url="../public/products.php?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>" data-did="#products" data-ref_id="#show_total" data-ref_url="../accounting/accounting_calc.php?show_total=yes&id=<?php echo $_GET["id"]?>">
            <td class="" style="">
              <input type="text" name="t1" class="form-control" style="" value="<?php echo $uAdi?>" placeholder="">
              <?php if($varyasyon=="var"){?>
                <select name="rb" data-placeholder="<?php echo $sdil[221]; //Varyasyon Seçiniz?>" style="width:30%; float: left; margin-left:10px;" class="form-control chosen-select" tabindex="8">
                  <option value=""><?php echo $sdil[133]; //Varyasyon?></option>
                  <?php $sql=mysqli_query($conn, "select * from genel where ne='varyant' and s1=".$rsfu["s2"]." order by t1 asc"); while($rb=mysqli_fetch_assoc($sql)){?>
                    <option value="<?php echo $rb["id"];?>" title="<?php echo $rb["id"];?>" style="color:#6699FF" <?php if ($rb["id"]==$rsfu["s6"]){?>Selected<?php }?>><?php echo $rb["t1"];?></option>
                  <?php }?>
                </select>
              <?php }?>
            </td>
            <td class="w8 mw8">
            <div class="input-group">
              <?php if(mysqli_num_rows($sqlu)<>0  and $f7==1 and $rsu["s5"] < $rsfu["s5"]){echo "<i class=\"fa fa-exclamation-triangle pa mt10 ml10 mpa mmt10 mml10 text-danger\"></i>";}?>
              <input type="number" name="fuadet" id="qty<?php echo $rsfu["id"]?>" class="form-control tar mtal" style="text-align:right; border:1px solid #ced4da73 !important" title="<?php if(($rsu["s5"]>=$rsfu["s5"] and $f7==1) or $f7==0){?>Stokta Var/Stoksuz<?php }else{?>Stokta Yok<?php }?>" value="<?php echo $rsfu["s5"]?>" onfocus="if(this.value == '0') { this.value = ''} "  onblur="if(this.value == '') { this.value='0'; }">
              <span class="input-group-addon" id="basic-addon1" style="padding: 5px;">
              <select size=1 name="t10" class="sfa sna" style="font-size: 9px; padding: 3px; border:0px !important;">
                <?php if(!empty($t28)){$sbirim = explode(',',$t28); foreach($sbirim as $sbrm) {$s++; if($s > 20) {$s = 1;}?>
					<option value="<?php echo $sbrm;?>" <?php if($rsfu["t10"]==$sbrm) {echo "Selected"; }?>><?php echo $sbrm;?></option>
				<?php }}?>
				</select>
              </span>
            </div>
          </td>
          <td class="w5 mw5">
            <input type="text" name="s4" class="form-control" style="border:0px; text-align:right;" value="<?php echo $rsfu["s4"]?>">
          </td>
          <td class="p0 mp0 w10 mw10" style="<?php if($_GET["islem"]<>"dservice"){echo "display:none;";}?>">
            <div class="input-group">
              <input type="text" name="fumaliyet" id="maliyet<?php echo $rsfu["id"]?>" class="form-control " style="border: 1px solid #ccc !important; text-align:right;" value="<?php echo sprice($rsfu["pb4"])?>">
              <span class="input-group-addon" id="basic-addon1" style="padding: 5px;">
                <select class="sfa sna" name="t6" id="at6" style="font-size: 16px; padding: 3px; border: 0px !important;">
                  <option value="TRY" <?php if($rsfu["t6"]=="TRY"){echo "selected";}?>>&#xf195;</option>
                  <option value="EUR" <?php if($rsfu["t6"]=="EUR"){echo "selected";}?>>&#xf153;</option>
                  <option value="USD" <?php if($rsfu["t6"]=="USD"){echo "selected";}?>>&#xf155;</option>
                  <option value="GBP" <?php if($rsfu["t6"]=="GBP"){echo "selected";}?>>&#xf154;</option>
                </select>
              </span>
            </div>
          </td>
          <td class="w10 mw10" style="<?php if($_GET["islem"]<>"dservice"){echo "display:none;";}?>">
            <input type="text" name="fulfiyat" id="ful<?php echo $rsfu["id"]?>" class="form-control" style="text-align:right; <?php if($rsfu["pb3"]<>0){echo "text-decoration: line-through;";}?>" value="<?php echo sprice($rsfu["pb3"])?>">
          </td>
          <td class="p0 mp0 w10 mw10">
            <div class="input-group">
              <input type="text" id="price<?php echo $rsfu["id"]?>" name="fufiyat" class="form-control " style="border: 1px solid #ccc !important;  text-align:right;" value="<?php echo sprice($rsfu["pb1"])?>">
              <span class="input-group-addon" id="basic-addon1" style="padding: 5px;">
                <select class="sfa sna" name="t2" style="font-size: 16px; padding: 3px; border: 0px !important;">
                  <option value="TRY" <?php if($rsfu["t2"]=="TRY"){echo "selected";}?>>&#xf195;</option>
                  <option value="EUR" <?php if($rsfu["t2"]=="EUR"){echo "selected";}?>>&#xf153;</option>
                  <option value="USD" <?php if($rsfu["t2"]=="USD"){echo "selected";}?>>&#xf155;</option>
                  <option value="GBP" <?php if($rsfu["t2"]=="GBP"){echo "selected";}?>>&#xf154;</option>
                </select>
              </span>
            </div>
          </td>
          <td class="w10 mw10">
            <input type="text" id="total<?php echo $rsfu["id"]?>" class="form-control " style="text-align:right;" value="<?php echo wprice($rsfu["pb1"]*$rsfu["s5"])?>" readonly>
          </td>
          <td class="w8 mw8">
            <div class="input-group-btn">
              <button class="btn btn-primary btn-update-row" type="button"><i class="fa fa-refresh"></i></button>
              <button class="btn btn-danger btn-delete-row" type="button" data-href="../<?php echo $folder?>/ajax.php?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&durum=usil&uid=<?php echo $rsfu["id"]?>&urunid=<?php echo $rsu["id"]?>" style="margin-left:2px;"><i class="fas fa-trash "></i></button>
            </div>
          </td>
        </tr>
        <tr id="x<?php echo $rsfu["id"]?>tr" style="display:none;padding: 0px;">
          <td colspan="<?php if($_GET["islem"]<>"dservice"){echo "6";}else{echo "8";}?>">
            <input type="checkbox" name="s3" value="1" class="fl mr5 mt5 mdn" <?php if($rsfu["s3"]==1){?>Checked<?php }?>>
            <div><textarea name="fun2" class="form-control w97 fl" style="height:34px;" placeholder="<?php echo ctranslate("Açıklama")?>"><?php echo $rsfu["n2"]?></textarea></div>
            <div id="x<?php echo $rsfu["id"]?>td"></div>
          </td>
        </tr>
        <script type='text/javascript'>
          jQuery(function(){
            jQuery("#qty<?php echo $rsfu["id"]?>, #price<?php echo $rsfu["id"]?>").keyup(function(){
              var qty = jQuery('#qty<?php echo $rsfu["id"]?>').val();
              var price = jQuery('#price<?php echo $rsfu["id"]?>').val();
              jQuery("#total<?php echo $rsfu["id"]?>").val(price*qty);
            });
            jQuery("#ful<?php echo $rsfu["id"]?>,#price<?php echo $rsfu["id"]?>").keyup(delay(function(){
              var lprice = jQuery('#ful<?php echo $rsfu["id"]?>').val();
              var price = jQuery('#price<?php echo $rsfu["id"]?>').val();
			  if(lprice <= price){ alert('<?php echo translate("#Liste fiyatı, ürünün satış rakamından az olamaz")?>'); }
            },1000));
            jQuery("#<?php echo $rsfu["id"]?>tr").click(function(){
              vtr('x<?php echo $rsfu["id"]?>tr');
              jQuery('#x<?php echo $rsfu["id"]?>td').load('../services/attr.php?uid=<?php echo $rsfu["s2"]?>&fid=<?php echo $rsfu["id"]?>');
            });
          });
        </script>
      </table>
    </form>
    <?php } //rsfu.movenext : loop ?>