"use strict";

appCore.controller("InvoiceAddCtrl", ["$state", "$scope", "$http", "$timeout", "vServices", "filterFilter", function ($state, $scope, $http, $timeout, vServices, filterFilter) {
    $scope.$root.page.title = "Add Invoice";
    $scope.param = $state.params;
    // console.log($scope.param);
    $scope.createButton = {
        heading: "Add Invoice",
        text: "Create Invoice",
        icon: "fa-save"
    };

    $scope.invoice = {
        attn:'',
        invoice_to:'',
        invoice_cc:'',
        company_code:'',
        project_code:'',
        invoice_approvar:'',
        company_name:'',
        description:''
    };

    $scope.createInvoice = (d) => {
        d = d;
        d.projectId=$scope.param.projectid;
        // console.log(d);
        vServices.callApi("invoices/addInvoice/", "POST",d)
        .then(function (res) {
            if (res) toastr.success(res, "Success!", {timeOut: 5000});
            $state.go($state.current, {}, {reload: true});
        });
    };
    
    const init = function () {
        let proId =$scope.param.projectid;
 
        vServices.callApi("invoices/singleInvoice?projId="+ proId ,  "GET")
        .then(function (res) {
            // console.log(res);
            $scope.invoice = res[0];
        });

       

    };
    init();
}
]);
