FACTURI DIALOG MAFRA

mail@pastecode.io avatar
unknown
html
2 years ago
33 kB
6
Indexable
Never
<template>
  <el-dialog title="Factura" :visible.sync="showPopup" :fullscreen="true" append-to-body :show-close="false"
    :close-on-press-escape="false">
    <el-form label-position="top" :inline="false" :rules="rules" label-width="100%" :model="selectedObject"
      ref="my-form" @submit.prevent="save" v-loading="loadingVisible" size="mini">
      <!-- <pre>{{this.selectedObject}}</pre> -->
      <el-row :gutter="15">
        <el-col :md="3">
          <el-form-item label="Client" prop="NumeClient" size="mini">
            <div class="input-group full-width">
              <el-select size="mini" v-model="selectedObject.NumeClient" @change="handleSelectClient" remote
                :remote-method="handleFind" filterable>
                <el-option v-for="item in Info.clienti" :key="item.Id + item.CodFiscal" id="client_cif"
                  :name="item.CodFiscal" :label="item.Nume" :value="item.Id">
                </el-option>
              </el-select>
              <div class="btn-a input-group-append">
                <el-button plain size="mini" type="success" icon="el-icon-plus" @click="show_add_new_client"
                  class="success" />
              </div>
            </div>
          </el-form-item>
        </el-col>
        <el-col :md="3">
          <el-form-item label="Internet">
            <el-switch v-model="selectedObject.Internet" true-label="1" false-label="0" active-text="Internet"
              @change="handleSelectInternet">
            </el-switch>
          </el-form-item>
        </el-col>
        <el-col :md="3">
          <el-form-item label="CIF">
            <el-input class="full-width" v-model="selectedObject.CifClient" :disabled="true" />
          </el-form-item>
        </el-col>
        <el-col :md="3">
          <el-form-item label="Reg. Com.">
            <el-input class="full-width" v-model="selectedObject.RegComClient" :disabled="true" />
          </el-form-item>
        </el-col>
        <el-col :md="3">
          <el-form-item label="Curs">
            <div class="full-width input-group">
              <el-input-number size="mini" v-model="selectedObject.Curs" :precision="4" controls-position="right"
                :step="0.01" @change="handleChangeCurs()" />
              <div class="btn-a input-group-append">
                <el-button style="margin-right: 16px" plain size="mini" type="primary" icon="el-icon-cloudy"
                  @click="selecteazaDataCurs()"></el-button>
                <el-date-picker :picker-options="datePickerOptions" popper-class="my-popover george"
                  style="display: none" ref="refDataCurs" v-model="selectedObject.DataCurs" type="date"
                  value-format="yyyy-MM-dd" format="dd.MM.yyyy" />
              </div>
            </div>
          </el-form-item>
        </el-col>
        <el-col :md="3">
          <el-form-item label="Serie" prop="IdSerie">
            <el-select class="full-width" v-model='selectedObject.IdSerie' filterable @change="handleSelectSerie">
              <el-option v-for="item in Info.serii" :key="item.Id" :label="item.Serie" :value="item.Id"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :md="3">
          <el-form-item label='Nr.'>
            <el-input class='full-width' v-model='selectedObject.Numar' :disabled="true" />
          </el-form-item>
        </el-col>
        <el-col :md="3">
          <el-form-item label="Gestiune" prop="IdGestiune" size="mini">
            <el-select size="mini" class="full-width" v-model="selectedObject.IdGestiune"
              @change="handleSelectGestiune()" filterable>
              <el-option v-for="item in Info.gestiuni" :key="item.Id + item.Nume" :label="item.Nume" :value="item.Id" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :md="3">
          <el-form-item label="Data emitere" prop="DataFactura" size="mini">
            <div class="full-width">
              <el-date-picker v-model="selectedObject.DataFactura" type="date" value-format="yyyy-MM-dd"
                format="dd.MM.yyyy" @change="handleSelectDataFactura" />
            </div>
          </el-form-item>
        </el-col>
        <el-col :md="3">
          <el-form-item label="Scadenta" prop="Scadenta" size="mini">
            <div class="full-width">
              <el-date-picker v-model="selectedObject.Scadenta" type="date" value-format="yyyy-MM-dd"
                format="dd.MM.yyyy" :default-value="null" />
            </div>
          </el-form-item>
        </el-col>
        <el-col :md="3">
          <el-form-item label="Discount %" prop="Discount" size="mini">
            <el-input-number class="full-width" v-model="selectedObject.Discount" controls-position="right"
              :precision="0" :min="0" :step="1" :max="100" @change="totalProduse()" />
          </el-form-item>
        </el-col>
        <el-col :md="3">
          <el-form-item label="Delegat" prop="IdDelegat" size="mini">
            <div class="full-width input-group">
              <el-select size="mini" v-model="selectedObject.IdDelegat" filterable>
                <el-option label="Fara" value="-1"></el-option>
                <el-option v-for="item in Info.delegati" :key="item.Id + item.Name" :label="item.Nume" :value="item.Id">
                </el-option>
              </el-select>
              <div class="btn-a input-group-append">
                <el-button plain size="mini" type="success" icon="el-icon-plus" @click="show_add_new_delegat"
                  class="success"></el-button>
              </div>
            </div>
          </el-form-item>
        </el-col>
        <el-col :md="3">
          <el-form-item label="Agent" prop="IdAgent" size="mini">
            <div class="full-width input-group">
              <el-select size="mini" v-model="selectedObject.IdAgent" filterable>
                <el-option label="Fara" value="-1"></el-option>
                <el-option v-for="item in Info.agenti" :key="item.Id + item.Denumire" :label="item.Denumire"
                  :value="item.Id">
                </el-option>
              </el-select>
              <div class="btn-a input-group-append">
                <el-button plain size="mini" type="success" icon="el-icon-plus" @click="show_add_new_agent"
                  class="success"></el-button>
              </div>
            </div>
          </el-form-item>
        </el-col>
        <el-col :md="3">
          <el-form-item label="Transport" prop="IdTransport" size="mini">
            <div class="input-group full-width">
              <el-select size="mini" v-model="selectedObject.IdTransport" filterable>
                <el-option label="Fara" value="-1"></el-option>
                <el-option v-for="item in Info.transportatori" :key="item.Id + item.Denumire" :label="item.Denumire"
                  :value="item.Id"></el-option>
              </el-select>
              <div class="btn-a input-group-append">
                <el-button plain size="mini" type="success" icon="el-icon-plus" @click="show_add_new_transport"
                  class="success"></el-button>
              </div>
            </div>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :md="24">
          <el-card shadow="hover">
            <div slot="header" class="clearfix" style="padding: 0px">
              <span>Produse</span>
            </div>
            <el-table class="produse" :data="selectedObject.Produse" :key="refreshTable">
              <el-table-column min-width="190px" label="Produs">
                <template slot-scope="scope">
                  <el-form-item :prop="'Produse[' + scope.$index + '].NumeProdus'"
                    :rules="{ required: true,  message: 'Campul este obligatoriu', trigger: 'blur', }">
                    <div class="input-group full-width">
                      <el-select size="mini" class="produs-input"
                        v-model="selectedObject.Produse[scope.$index].IdProdus"
                        @change="handleSelectProdus(scope.$index)" filterable>
                        <el-option v-for="item in Info.ProdusePtSelect" :key="item.Id" :id="selectedObject.IdGestiune == '' ||
                        selectedObject.IdGestiune == null ||
                        selectedObject.IdGestiune == undefined ? '' : 'produs_cu_stoc'"
                          :name="'Stoc: ' + (item.Intrari - item.Iesiri)" :label="item.Nume" :value="item.Id">
                        </el-option>
                      </el-select>
                      <div v-if="selectedObject.Produse[scope.$index].IdProdus != 0" class="btn-a input-group-append">
                        <el-button plain size="mini" type="success" icon="el-icon-plus"
                          @click="show_add_new_produs(scope.$index)" class="success"></el-button>
                      </div>
                    </div>
                  </el-form-item>
                  <!-- </div> -->
                </template>
              </el-table-column>
              <el-table-column min-width="50px" label="Cantitate" align="center">
                <template slot-scope="scope">
                  <el-form-item :prop="'Produse[' + scope.$index + '].Cantitate'"
                    :rules="{ required: true, message: 'Campul este obligatoriu', trigger: 'blur',}">
                    <el-input-number size="mini" class="full-width"
                      v-model="selectedObject.Produse[scope.$index].Cantitate" :precision="0" :min="0" :step="1"
                      @change="totalProduse()" />
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column min-width="55px" label="P.U." align="center">
                <template slot-scope="scope">
                  <!-- <div v-if="!scope.row.Edited"> {{ scope.row.PretFaraTVA }} </div> -->
                  <!-- <div v-else> -->
                  <el-form-item :prop="'Produse[' + scope.$index + '].PretFaraTVA'"
                    :rules="{ required: true,  message: 'Campul este obligatoriu', trigger: 'blur', }">
                    <el-input-number size="mini" class="full-width"
                      v-model="selectedObject.Produse[scope.$index].PretFaraTVA" :precision="2"
                      controls-position="right" :step="0.01" @change="totalProduse()" />
                  </el-form-item>
                  <!-- </div> -->
                </template>
              </el-table-column>
              <el-table-column min-width="50px" label="Valoare (cu discount)" align="center">
                <template slot-scope="scope">
                  <span
                    v-if="selectedObject.Produse[scope.$index].ValoareFaraTVA >= 0">{{selectedObject.Produse[scope.$index].ValoareFaraTVA}}</span>
                  <span v-else>-</span>
                </template>
              </el-table-column>
              <el-table-column min-width="60px" label="P.U. Eur" align="center">
                <template slot-scope="scope">
                  <!-- <div v-if="!scope.row.Edited">{{ parseFloat(scope.row.PretFaraTVAEur).toFixed(4) }}</div> -->
                  <!-- <div v-else> -->
                  <el-form-item :prop="'Produse[' + scope.$index + '].PretFaraTVAEur'"
                    :rules="{ required: true,  message: 'Campul este obligatoriu', trigger: 'blur', }">
                    <el-input-number size="mini" class="full-width"
                      v-model="selectedObject.Produse[scope.$index].PretFaraTVAEur" :precision="4"
                      controls-position="right" :step="0.0001" @change="handlePUEur(scope.$index)" />
                    <!-- @change="selectedObject.Produse[scope.$index].PretFaraTVA = selectedObject.Produse[scope.$index].PretFaraTVAEur * selectedObject.Curs" -->
                  </el-form-item>
                  <!-- </div> -->
                </template>
              </el-table-column>
              <el-table-column min-width="40px" label="Cota TVA" align="center">
                <template slot-scope="scope">
                  <!-- <div v-if="!scope.row.Edited">{{ scope.row.ProcentTVA }}</div> -->
                  <!-- <div v-else> -->
                  <el-form-item :prop="'Produse[' + scope.$index + '].IdTVA'"
                    :rules="{ required: true,  message: 'Campul este obligatoriu', trigger: 'blur', }">
                    <el-select size="mini" class="full-width select_dreapta"
                      v-model="selectedObject.Produse[scope.$index].IdTVA" @change="handleSelectTVA(scope.$index)">
                      <el-option v-for="item in Info.listaTVA" :key="item.Id" :label="item.Procent" :value="item.Id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <!-- </div> -->
                </template>
              </el-table-column>
              <el-table-column align="center" fixed="right" label="Actiuni" width="100px">
                <template slot-scope="scope">
                  <span>
                    <el-tooltip content="Sterge">
                      <el-button size="mini" type="danger" icon="el-icon-delete" circle @click="sterge(scope.$index)" />
                    </el-tooltip>
                    <el-tooltip content="Storneaza">
                      <el-button size="mini" type="warning" icon="el-icon-sold-out" circle
                        @click="storneaza_linie(scope.$index)" />
                    </el-tooltip>
                  </span>
                </template>
              </el-table-column>
            </el-table>
            <el-button @click="rand_nou()"> + </el-button>
            <el-row v-if="selectedObject.arata_total == true">
              <el-col class="tabel-valori">
                <table cellpadding="10" class="tabel-data" style="margin-top: 10px; width: 70%">
                  <tr class="cell-data">
                    <th>Valoare totala fara TVA</th>
                    <td align="right"> {{ selectedObject.ValoareFaraTVA | format_money }}</td>
                  </tr>
                  <tr class="cell-data">
                    <th>Valoare TVA</th>
                    <td align="right"> {{ selectedObject.ValoareTVA | format_money }} </td>
                  </tr>
                  <tr class="cell-data">
                    <th>Valoare totala cu TVA</th>
                    <td align="right"> {{ selectedObject.ValoareCuTVA | format_money }} </td>
                  </tr>
                  <tr v-if="selectedObject.Discount > 0" class="cell-data">
                    <th>Discount</th>
                    <td align="right"> {{ selectedObject.Discount}}% </td>
                  </tr>
                </table>
              </el-col>
            </el-row>
          </el-card>
        </el-col>
      </el-row>
    </el-form>

    <span slot="footer" class="dialog-footer">
      <el-button @click="resetForm('my-form')"> Renunta </el-button>
      <el-button type="primary" @click="save('my-form')"> Salveaza </el-button>
    </span>
    <!-- <pre>{{ this.selectedObject }}</pre> -->
    <Delegati-dialog ref="dlg-delegat-nou" @save="salvare_delegat" />
    <Agenti-dialog ref="dlg-agent-nou" @save="salvare_agent" />
    <Produse-dialog ref="dlg-produs-nou" @save="salvare_produs" />
    <Clienti-dialog ref="dlg-client-nou" @save="salvare_client" />
    <Transport-dialog ref="dlg-transport-nou" @save="salvare_transport" />
  </el-dialog>
</template>

<script>
import moment from "moment";
import settings from "@/backend/LocalSettings";
import BasePage from "@/pages/BasePage";
import Agenti_dialog from "@/pages/agenti/Agenti_dialog.vue";
import Produse_dialog from "@/pages/produse/Produse_dialog.vue";
import Clienti_dialog from "@/pages/clienti/Clienti_dialog.vue";
import Delegati_dialog from "@/pages/delegati/Delegati_dialog.vue";
import Transport_dialog from "@/pages/transport/Transport_dialog.vue";

export default {
  name: "Facturi_dialog",
  extends: BasePage,
  components: {
    "Delegati-dialog": Delegati_dialog,
    "Agenti-dialog": Agenti_dialog,
    "Produse-dialog": Produse_dialog,
    "Clienti-dialog": Clienti_dialog,
    "Transport-dialog": Transport_dialog,
  },
  data() {

    return {
      datePickerOptions: {
        disabledDate(date) {
          return date > new Date()
        },
      },
      refreshTable: 0,
      showPopup: false,
      mode: "add",
      selectedObject: {},
      selectedObjectTemplate: {
        Internet: "0",
        DataFactura: "",
        IdSerie: "",
        Numar: "",
        IdClient: "",
        Curs: "1",
        IdDelegat: "-1",
        IdAgent: "-1",
        IdGestiune: "",
        IdTransport: "-1",
        Scadenta: null,
        Discount: 0,
        NumeClient: "",
        CifClient: "",
        RegComClient: "",
        Produse: [],
        TermenPlataDefaultClient: "",
        IdGestiuneDefaultClient: "",
        Produse: [],
        arata_total: false,
      },
      produsTemplate: {
        IdProdus: "",
        NumeProdus: "",
        Cantitate: "",
        PretFaraTVA: "",
        PretCuTVA: "",
        PretFaraTVAEur: "",
        IdTVA: "",
        ProcentTVA: "",
        ValoareTVA: "",
        ValoareCuTVA: "",
        ValoareFaraTVA: "",
      },
      Info: {
        listaTVA: [],
        gestiuni: [],
        clienti: [],
        clientiOld: [],
        delegati: [],
        transportatori: [],
        produse: [],
      },
      rules: {
        Numar: [{ required: true, message: "Campul este obligatoriu" }],
        IdSerie: [{ required: true, message: "Campul este obligatoriu" }],
        IdGestiune: [{ required: true, message: "Campul este obligatoriu" }],
        DataFactura: [{ required: true, message: "Campul este obligatoriu" }],
        NumeClient: [{ required: true, message: "Campul este obligatoriu" }],
        // CifClient: [{ required: true, message: "Campul este obligatoriu" }],
        // RegComClient: [ { required: true, message: "Campul este obligatoriu" }],
        PretFaraTVA: [{ required: true, message: "Campul este obligatoriu" }],
        Gestiune: [{ required: true, message: "Campul este obligatoriu" }],
        IdProdus: [{ required: true, message: "Campul este obligatoriu" }],
        PretFaraTVA: [{ required: true, message: "Campul este obligatoriu" }],
        Cantitate: [{ required: true, message: "Campul este obligatoriu" }],
        IdTVA: [{ required: true, message: "Campul este obligatoriu" }],
      },
    };
  },
  watch: {
    'selectedObject.DataCurs'(newselectedObject, oldselectedObject) {
      if (typeof oldselectedObject !== 'undefined' && this.selectedObject.DataCurs != null) {
        this.getCurs(newselectedObject)
      }
    }
  },
  methods: {
    show_me: async function (id) {
      await this.get_info();
      this.selectedObject = this.selectedObjectTemplate;

      if (id == null) {
        this.mode = "add";
        this.selectedObject.IdSerie = this.IdSerieImplicitaUser;
      } else {
        this.mode = "edit";
        var result = await this.post("facturi/get_info_item_dialog", { id: id });
        this.selectedObject = result.Item;
        this.handleSelectGestiune();
        await this.handleInternet('get');
        this.totalProduse();
      }
      this.minim1Produs();
      this.showPopup = true;
    },
    async getCurs(dataCurs) {
      var response = await this.post("curs_bnr/getCurs", { data: dataCurs })
      if (response.fx) {
        this.selectedObject.Curs = response.fx;
      } else {
        this.selectedObject.DataCurs = null;
      }
      this.totalProduse();
    },

    async get_info() {
      var response = await this.post("facturi/get_info_for_dialog");
      // this.Info  = response;
      this.Info.clientiOld = [...response.clienti];
      this.Info.agenti = response.agenti;
      this.Info.listaTVA = response.listaTVA;
      this.Info.gestiuni = response.gestiuni;
      this.Info.delegati = response.delegati;
      this.Info.serii = response.serii;
      this.Info.transportatori = response.transportatori;
      this.Info.produse = response.produse;
      this.Info.clienti = response.clienti;
      this.Info.produseToateGestiunile = response.produseToateGestiunile;
      this.IdSerieImplicitaUser = response.User.IdSerieImplicita;
    },

    selecteazaDataCurs() {
      this.$refs['refDataCurs'].pickerVisible = true;
    },

    handleChangeCurs() {
      this.selectedObject.DataCurs = null;
      this.totalProduse();
    },
    totalProduse() {

      if (this.selectedObject.Produse.length > 0) {
        var TotalValoareCuTva = [];
        var TotalValoareTva = [];
        var TotalValoareFaraTva = [];
        this.selectedObject.Produse.forEach((el) => {

          el.ValoareFaraTVA = parseFloat(el.PretFaraTVA * el.Cantitate * (100 - this.selectedObject.Discount) / 100).toFixed(2);
          el.ValoareTVA = parseFloat((el.ValoareFaraTVA * (0 + "." + el.ProcentTVA))).toFixed(2);
          el.ValoareCuTVA = Number(el.ValoareFaraTVA) + Number(el.ValoareTVA);
          el.PretFaraTVAEur = el.PretFaraTVA / this.selectedObject.Curs

          TotalValoareFaraTva.push(parseFloat(el.ValoareFaraTVA).toFixed(2));
          TotalValoareCuTva.push(parseFloat(el.ValoareCuTVA).toFixed(2));
          TotalValoareTva.push(parseFloat(el.ValoareTVA).toFixed(2));


        });

        this.selectedObject.ValoareCuTVA = TotalValoareCuTva.reduce((a, b) => Number(a) + Number(b));
        this.selectedObject.ValoareFaraTVA = TotalValoareFaraTva.reduce((a, b) => Number(a) + Number(b));
        this.selectedObject.ValoareTVA = TotalValoareTva.reduce((a, b) => Number(a) + Number(b));
        this.selectedObject.arata_total = true;

        this.refreshTable++;
      }
    },
    minim1Produs() {
      if (this.selectedObject.Produse.length == 0) {
        this.rand_nou()
      }
    },
    rand_nou() {
      var tvaImplicit = this.Info.listaTVA.filter((item) => item.Implicit == 1)[0];
      let nou = {
        Id: "",
        Cantitate: 1,
        PretCuTVA: 0,
        ValoareTva: 0,
        ValoareCuTVA: 0,
        // Edited: true,
        IdTVA: tvaImplicit.Id,
        // ValoareTva: parseFloat(tvaImplicit.Procent).toFixed(2) ,
        ProcentTVA: parseFloat(tvaImplicit.Procent).toFixed(0),
      };
      // if(this.selectedObject.Produse.length == 0 || typeof this.Info.ProdusePtSelect == 'undefined' ){
      //   this.Info.ProdusePtSelect = [];
      // }

      // this.Info.ProdusePtSelect[this.selectedObject.Produse.length] = this.Info.produse;
      this.selectedObject.Produse.push(nou);
      this.refreshTable++;
    },
    async sterge(row) {
      this.$confirm(`Sunteti sigur ?`, "Warning", {
        type: "warning",
      })
        .then(async () => {
          this.selectedObject.Produse.splice(row, 1);
          this.totalProduse();
          this.minim1Produs();
          this.refreshTable++;
        })
        .catch(() => {
          // this.$message({type: 'info', message: 'Stergere anulata'});
        });
    },

    async storneaza_linie(row) {

      alert('nu se salveaza modificarile')
    },
    show_add_new_client() {
      this.$refs["dlg-client-nou"].show_me();
    },
    show_add_new_transport() {
      this.$refs["dlg-transport-nou"].show_me();
    },
    show_add_new_produs(index) {
      this.$refs["dlg-produs-nou"].show_me(null, index);
    },
    show_add_new_delegat() {
      this.$refs["dlg-delegat-nou"].show_me();
    },
    show_add_new_agent() {
      this.$refs["dlg-agent-nou"].show_me();
    },
    async salvare_client(insertedObj) {
      await this.get_info();
      this.handleSelectClient(insertedObj.Id)
      this.totalProduse();
    },
    async salvare_transport(insertedObj) {
      await this.get_info();
      this.selectedObject.IdTransport = String(insertedObj.Id);
    },
    async salvare_delegat(insertedObj) {
      await this.get_info();
      this.selectedObject.IdDelegat = String(insertedObj.Id);
    },
    async salvare_agent(insertedObj) {
      await this.get_info();
      this.selectedObject.IdAgent = String(insertedObj.Id);
    },
    async handlePUEur(item) {
      this.selectedObject.Produse[item].PretFaraTVA = this.selectedObject.Produse[item].PretFaraTVAEur * this.selectedObject.Curs;
      this.totalProduse();
    },
    async salvare_produs(insertedObj) {
      await this.get_info();
      this.selectedObject.Produse[insertedObj.numar_linie].IdProdus = String(insertedObj.Id);
      this.selectedObject.Produse[insertedObj.numar_linie].NumeProdus = insertedObj.Nume;
      this.Info.ProdusePtSelect = this.Info.produseToateGestiunile[this.selectedObject.IdGestiune];
      this.handleSelectProdus(insertedObj.numar_linie);
      this.refreshTable++;
    },
    handleSelectProdus(item) {
      var idProdusSelectat = this.selectedObject.Produse[item].IdProdus;
      if (typeof idProdusSelectat !== 'undefined') {
        let produs = this.Info.produse.filter((prod) => prod.Id == idProdusSelectat)[0];
        this.selectedObject.Produse[item].NumeProdus = produs.Nume;
        if (this.selectedObject.Internet == 1) {
          this.selectedObject.Produse[item].PretFaraTVA = produs.PretInternet;
        } else {
          let pretPersonalizat = this.Info.produse.filter((prod) => prod.Id == this.selectedObject.Produse[item].IdProdus)[0].personalizari;
          let pret_client_selectat = pretPersonalizat.filter((xxx) => xxx.IdClient == this.selectedObject.IdClient);
          if (pret_client_selectat.length > 0 && pretPersonalizat.length > 0 && this.selectedObject.IdClient > 0) {
            this.selectedObject.Produse[item].PretFaraTVA = pret_client_selectat[0].PretPersonalizat;
          } else {
            this.selectedObject.Produse[item].PretFaraTVA = produs.Pret;
          }
        }
        if (this.selectedObject.Produse[item].IdGestiune == 0) {
          if (this.selectedObject.IdGestiuneDefaultClient > 0) {
            this.selectedObject.Produse[item].IdGestiune = this.selectedObject.IdGestiuneDefaultClient;
          } else {
            this.selectedObject.Produse[item].IdGestiune = "";
          }
        }

        this.selectedObject.Produse[item].PretFaraTVAEur = this.selectedObject.Produse[item].PretFaraTVA / this.selectedObject.Curs
      }
      this.selectedObject.Produse.splice(this.selectedObject.Produse.length)
      this.totalProduse();
    },

    handleSelectTVA(item) {
      this.selectedObject.Produse[item].ProcentTVA = this.Info.listaTVA[this.selectedObject.Produse[item].IdTVA - 1].Procent;
      this.totalProduse();
    },
    handleSelectGestiune() {
      this.Info.ProdusePtSelect = this.Info.produseToateGestiunile[this.selectedObject.IdGestiune]
      this.selectedObject.Produse.splice(this.selectedObject.Produse.length)
    },
    handleSelectInternet() {
      this.selectedObject.Produse.forEach((el, index) => {
        this.handleSelectProdus(index)
      });
      this.totalProduse();
    },
    async handleSelectSerie() {
      if (this.mode == 'edit' && this.selectedObject.IdSerie == this.selectedObject.IdSerieInitiala) {
        this.selectedObject.Numar = this.selectedObject.NumarInitial;
      } else {
        var response = await this.post("facturi/get_numar_serie", { id_serie: this.selectedObject.IdSerie })
        this.selectedObject.Numar = response.NumarNou;
      }
    },
    handleInternet: async function (mode) {
      if (mode === 'save') {
        if (this.selectedObject.Internet) {
          this.selectedObject.Internet = '1';
        } else {
          this.selectedObject.Internet = '0'
        }
      } else if (mode === 'get') {
        if (this.selectedObject.Internet == '1') {
          this.selectedObject.Internet = true;
        } else {
          this.selectedObject.Internet = false;
        }
      }
    },

    async handleFind(data) {
      this.Info.clienti = [];
      if (data != "") {
        this.Info.clientiOld.forEach(element => {
          if ((element.Nume).toLowerCase().indexOf(data) != -1 || (element.CodFiscal != null && (element.CodFiscal).indexOf(data) != -1)) {
            this.Info.clienti.push(element);
          }
        })
      } else {
        this.Info.clienti = this.Info.clientiOld.slice();
      }
    },

    handleSelectClient(idFz) {

      let item = this.Info.clienti.filter((client) => client.Id == idFz)[0];
      if (parseInt(item.id) < 0) {
        this.selectedObject.NumeClient = "";
      } else {
        var client = item;
        this.selectedObject.IdClient = client.Id;
        this.selectedObject.CifClient = client.CodFiscal;
        this.selectedObject.RegComClient = client.RegCom;
        this.selectedObject.NumeClient = client.Nume;
        this.selectedObject.TermenPlataDefaultClient = Number(client.TermenPlata);
        this.selectedObject.DiscountDefaultClient = Number(client.Discount);
        if (client.IdGestiuneDefault !== null && this.selectedObject.IdGestiune == '') {
          this.selectedObject.IdGestiune = client.IdGestiuneDefault;
        }

        this.Info.ProdusePtSelect = this.Info.produseToateGestiunile[this.selectedObject.IdGestiune]
        this.selectedObject.Produse.forEach((el, index) => {
          this.handleSelectProdus(index)
        });
        this.totalProduse();
        this.selectedObject.Produse.splice(this.selectedObject.Produse.length)

        if (this.selectedObject.DataFactura && this.selectedObject.TermenPlataDefaultClient > 0) {
          var scadenta = moment(this.selectedObject.DataFactura).add(this.selectedObject.TermenPlataDefaultClient, 'days');
          this.selectedObject.Scadenta = scadenta.format('YYYY-MM-DD');
        }

        this.selectedObject.Discount = this.selectedObject.DiscountDefaultClient;

      }
    },
    handleSelectDataFactura(data) {
      if (this.selectedObject.DataFactura && this.selectedObject.TermenPlataDefaultClient > 0) {
        var scadenta = moment(this.selectedObject.DataFactura).add(this.selectedObject.TermenPlataDefaultClient, 'days');
        this.selectedObject.Scadenta = scadenta.format('YYYY-MM-DD');
      }
    },
    save: async function () {
      this.$refs["my-form"].validate(async (valid) => {
        if (valid) {
          this.handleInternet('save');
          await this.post("facturi/save", {
            mode: this.mode,
            object: this.selectedObject,
          });
          this.resetForm();
          this.$emit("save");
        } else console.log("eroare validare formular!");
      });
    },
    resetForm() {
      this.$refs["my-form"].resetFields();
      this.showPopup = false;
    },
  },
  mounted: function () {
    this.get_info();
  },

};

</script>

<style lang="less" scoped>
#client_cif {
  margin: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 10px;
}

#client_cif:after {
  content: 'CIF: ' attr(name);
  width: auto;
  max-height: 27px !important;
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
  float: right;
  font-size: 10px !important;
  padding: 0 5px;
  margin: 2px 0;
  border: 1px solid transparent;
  border-radius: 7px;
  background-color: #40a0ffa1;
}

#produs_cu_stoc:after {
  content: attr(name);
  width: auto;
  max-height: 27px !important;
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
  float: right;
  font-size: 10px !important;
  padding: 0 5px;
  margin: 2px 0;
  border: 1px solid transparent;
  border-radius: 7px;
  background-color: #40a0ffa1;
}

/deep/ .el-input-number .el-input__inner {
  text-align: right;
}

/deep/ .select_dreapta .el-input__inner {
  text-align: right;
}

.full-width {
  width: 100% !important;

  .el-input {
    width: 85% !important;
  }

  .el-input-number {
    width: 85% !important;
  }

  .el-select {
    width: 85% !important;
  }


  .produs-input .el-select {
    width: 100% !important;
  }



  .el-date-editor.el-input {
    width: 100% !important;
  }

  .btn-a {
    margin: 0;
    padding: 0;
    width: 15% !important;

    .el-button {
      width: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
}

.el-table .el-form-item {
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
}

.tabel-valori {
  width: 100%;
  display: flex;
  justify-content: flex-end;
}

.tabel-data {
  width: 300px !important;
  word-break: keep-all;

}



@media only screen and (max-width: 768px) {
  .tabel-data {
    width: 75% !important;
    font-size: 14px;
  }
}

.el-row {
  margin-bottom: 20px;

  &:last-child {
    margin-bottom: 0;
  }
}
</style>