"use strict";

appCore.controller("ManPowerPlanningDiscussionsAddCtrl", ["$state", "$scope", "$http", "$timeout", "vServices", "filterFilter", function ($state, $scope, $http, $timeout, vServices, filterFilter) {
    $scope.$root.page.title = "Manpower Planning / Resource requirement discussions";
    $scope.createButton = {heading: "Add", text: "Save", icon: "fa-save", today: new Date()};
    $scope.manPowerPlanningDiscussionsAdd = {'meeting_date': null, 'meeting_notes': '', 'meeting_attendees': '', 'meeting_attachment': null};
    let dupHandler = [];

    let dummyEntry = {proj_id: "", emp_id: $scope.$root.gUser.id, date: null, reference: "", description: "", logtype: "0", hours: 0, comments: ""};


    $scope.Save = () => {
        let data = $scope.manPowerPlanningDiscussionsAdd;
        console.log(data);
        let attachment = {'attachment': data.meeting_attachment};
        delete data.meeting_attachment;
        if (data.meeting_notes !== '' && data.meeting_attendees !== '' && data.meeting_date !== null) {
            vServices.callApi("employee/addManPowerPlanningDiscussion", "POST", data, attachment).then((res) => {
                if (res) {
                    $state.go("manPowerPlanningDiscussionsList", {}, {reload: true});
                }
            });
        }
        else toastr.error('Unable to submit partially filled data, kindly validate.');
    }, (e) => {
        console.log(e);
    };

}]);
