import{a as Z,b as K}from"./chunk-S4UARQQV.js";import{a as z,b as j}from"./chunk-MXSLISEG.js";import"./chunk-7QEXVS2A.js";import"./chunk-HXEFMD5A.js";import"./chunk-KCLQIV7M.js";import"./chunk-5KCUTXXV.js";import"./chunk-JUDWAYYT.js";import{a as Y}from"./chunk-5OT2MLHH.js";import{a as h}from"./chunk-WFZJP5WR.js";import"./chunk-F6KLNSUK.js";import{a as X}from"./chunk-4MZCYQX4.js";import{b as $,c as W,d as q}from"./chunk-YOJ4KGSB.js";import"./chunk-I6FSQTEP.js";import"./chunk-CO3X7TQN.js";import{a as V}from"./chunk-VSFNMVXJ.js";import"./chunk-WQ6DP4JQ.js";import{Mb as k,Ob as F,Va as w,Wa as P,Za as D,a as oe,tb as v,wb as G}from"./chunk-YSQLW2JA.js";import"./chunk-NVJ2ZZFT.js";import{Dc as A,Fb as E,Hb as _,He as u,Mg as x,Ng as B,Pd as O,Rd as d,Sd as R,Se as U,Te as f,Ue as L,_a as b,ab as C,af as g,bb as c,cd as T,dd as m,g as ne,gb as I,hd as p,kb as N,kg as M,ng as y,ya as l}from"./chunk-SKPDQO4E.js";var Q=`<div class="h-100">
    <side-navigation *ngIf="visibleComponent">
        <ng-template side-navigation-nav>
            <div class="row">
                <div class="col-12" *ngIf="permissionSearchOrganizationUnit">
                    <label class="report-form-label">{{'REPORT.ORGANIZATION_UNITS' | translate}}</label>
                    <armon-select-search query="unit" [allowMulti]="true" [(ngModel)]="filter.organizationUnitIds"
                        (ngModelChange)="onFilterUpdated($event)">
                    </armon-select-search>
                </div>
                <div class="col-12" *ngIf="permissionSearchUserGroup">
                    <label class="report-form-label">{{'REPORT.USER_GROUPS' | translate :
                        languageService.userTranslate}}</label>
                    <armon-select-search query="group" [allowMulti]="true" [(ngModel)]="filter.userGroupIds"
                        (ngModelChange)="onFilterUpdated($event)">
                    </armon-select-search>
                </div>
                <div class="col-12" *ngIf="permissionSearchIdentity">
                    <label class="report-form-label">{{'IDENTITY.TITLE' | translate :
                        languageService.userTranslate}}</label>
                    <armon-select-search query="identity" [allowMulti]="true" [(ngModel)]="filter.userIds"
                        (ngModelChange)="onFilterUpdated($event)">
                    </armon-select-search>
                </div>
            </div>
            <!-- Buttons for filtering state -->
            <div class="centered filterButtons">
                <button class="btn btn-success btn-sm" (click)="onGetExcelClicked($event)">{{'BUTTON.EXCEL'
                    | translate}}</button>
            </div>
        </ng-template>
        <ng-template side-navigation-content>
            <div class="row my-3">
                <div class="col-12">
                    <button class="btn btn-sm btn-primary"
                        (click)="onNewActionClicked($event)">{{'SOCA.BALANCE_NEW_ACTION'|translate}}</button>
                </div>
            </div>
            <div class="row">
                <div class="col-12">
                    <p-table [value]="balances" dataKey="userId" [responsive]="true" rowExpandMode="single">
                        <ng-template pTemplate="header">
                            <tr>
                                <th>{{'SOCA.BALANCE_FULLNAME' | translate}}</th>
                                <th class="width-20p">{{'SOCA.BALANCE_REMAINING_UNITS' | translate}}</th>
                                <th class="width-20p">{{'SOCA.BALANCE_TOTAL_SPENT_UNITS' | translate}}</th>
                            </tr>
                        </ng-template>
                        <ng-template pTemplate="body" let-balance let-rowData let-expanded="expanded">
                            <tr [pRowToggler]="rowData" [attr.expanded]="expanded" class="data-row">
                                <td>
                                    <span *ngIf="balance.user && !balance.userCaptions">{{balance.user.fullname}}</span>
                                    <armon-captionlines *ngIf="balance.userCaptions" [showBorder]="false"
                                        [captionlines]="balance.userCaptions"></armon-captionlines>
                                </td>
                                <td>
                                    <div class="report-multi-data-cell">
                                        <span class="main-text">{{balance.remainingUnits|number}}</span>
                                        <span class="sub-text">{{'SOCA.BALANCE_UNIT' | translate}}</span>
                                    </div>
                                </td>
                                <td>
                                    <div class="report-multi-data-cell">
                                        <span class="main-text">{{balance.totalSpentUnits|number}}</span>
                                        <span class="sub-text">{{'SOCA.BALANCE_UNIT' | translate}}</span>
                                    </div>
                                </td>
                            </tr>
                        </ng-template>
                        <ng-template pTemplate="rowexpansion" let-balance>
                            <tr>
                                <td [attr.colspan]="3" class="expanded-row px-3">
                                    <div class="d-flex align-items-center py-2 my-2 b-b-1">
                                        <span>{{balance.user.fullname}}</span>
                                    </div>
                                    <div class="d-flex my-2">
                                        <button class="btn btn-sm btn-outline-primary me-2"
                                            (click)="gotoUserUsageReport(balance.userId)">{{'PAGES.SOCA_REPORT_USAGES'|translate}}</button>
                                        <button class="btn btn-sm btn-outline-primary"
                                            (click)="gotoUserTransactionReport(balance.userId)">{{'PAGES.SOCA_REPORT_TRANSACTIONS'|translate}}</button>
                                    </div>
                                </td>
                            </tr>
                        </ng-template>
                    </p-table>
                </div>
            </div>
            <div class="row pb-3">
                <div class="col-12">
                    <armon-pagination [paginationResponse]="paginationResponse" (pageChanged)="pageChanged($event)">
                    </armon-pagination>
                </div>
            </div>
        </ng-template>
    </side-navigation>
</div>`;var H="";var J=`<ng-container *ngIf="visibleComponent">
  <div class="modal-header">
    <span class="text-lg" *ngIf="form">{{(form.get('increment').value ? 'SOCA.BALANCE_NEW_ACTION' :
      'SOCA.BALANCE_NEW_ACTION_DECREMENT' ) |
      translate}}</span>
  </div>
  <div class="modal-body">
    <ng-container *ngIf="upsertMode">
      <form [formGroup]="form">
        <div class="row">
          <div class="col-12 mb-3">
            <div class="form-group">
              <label for="amountInput">{{'SOCA.BALANCE_NEW_ACTION_AMOUNT' | translate}}</label>
              <input type="text" class="form-control form-control-lg w-50"
                [ngClass]="{'is-invalid': form.get('amount').touched && form.get('amount').invalid}"
                [formControl]="form.get('amount')" id="amountInput">
              <ng-template
                *ngTemplateOutlet="controlValidationTemplate; context: {$implicit: form, control:form.get('amount')}">
              </ng-template>
            </div>
          </div>
          <div class="col-12">
            <div class="form-group">
              <label>{{'SOCA.BALANCE_NEW_ACTION_LABEL' | translate}}</label>
              <div>
                <div class="form-check form-check-inline">
                  <input class="form-check-input cursor-pointer" type="radio" name="incrementRadioOptions"
                    id="incrementRadioTrue" [value]="true" [formControl]="form.get('increment')">
                  <label class="form-check-label" for="incrementRadioTrue">{{'SOCA.BALANCE_NEW_ACTION_ADD' |
                    translate}}</label>
                </div>
                <div class="form-check form-check-inline">
                  <input class="form-check-input cursor-pointer" type="radio" name="incrementRadioOptions"
                    id="incrementRadioFalse" [value]="false" [formControl]="form.get('increment')">
                  <label class="form-check-label" for="incrementRadioFalse">{{'SOCA.BALANCE_NEW_ACTION_REMOVE' |
                    translate}}</label>
                </div>
              </div>

            </div>
          </div>
          <div class="col-12">
            <div class="form-group">
              <label for="noteInput">{{'SOCA.BALANCE_NEW_ACTION_NOTE' | translate}}</label>
              <input type="text" maxlength="255" class="form-control form-control-sm"
                [ngClass]="{'is-invalid': form.get('note').touched && form.get('note').invalid}"
                [formControl]="form.get('note')" id="noteInput">
              <ng-template
                *ngTemplateOutlet="controlValidationTemplate; context: {$implicit: form, control:form.get('note')}">
              </ng-template>
            </div>
          </div>
        </div>
      </form>
    </ng-container>
    <ng-container *ngIf="!upsertMode">
      <div class="row">
        <div class="col-12">
          <div class="alert alert-danger alert-sm mb-4">
            <div class="alert-items">
              <div class="alert-item static">
                <div class="alert-text">
                  {{'SOCA.BALANCE_NEW_ACTION_FAILED_USERS'|translate}}
                </div>
              </div>
            </div>
          </div>
        </div>
        <ng-container *ngFor="let failedUser of failedUsers">
          <div class="col-12">
            <div class="d-flex flex-column shadow-box-1 p-2 mb-3">
              <armon-captionlines *ngIf="failedUser.captionLines" [showBorder]="false" class="mb-2"
                [captionlines]="failedUser.captionLines"></armon-captionlines>
              <span class="text-sm text-danger mx-1">{{failedUser.message}}</span>
            </div>
          </div>
        </ng-container>
      </div>
    </ng-container>
  </div>
  <div class="modal-footer">
    <button class="btn btn-outline-primary me-2" (click)="onCancelClicked($event)">{{'BUTTON.CLOSE' |
      translate}}</button>
    <button class="btn btn-primary" (click)="onSaveClicked($event)" *ngIf="upsertMode" [disabled]="form.invalid">
      {{'SOCA.BALANCE_NEW_ACTION_SELECT_USERS' | translate}}
    </button>
  </div>
</ng-container>


<!-- FORM FIELD VALIDATION -->
<ng-template #controlValidationTemplate let-form let-control="control">
  <ng-container *ngIf="control.errors">
    <div class="invalid-feedback d-flex flex-column" style="display: initial;">
      <span *ngIf="control.errors.required">{{'VALIDATION.REQUIRED'|translate}}</span>
      <span *ngIf="control.errors.numeric">{{'VALIDATION.POSITIVE_NUMBER'|translate}}</span>
      <span *ngIf="control.errors.pattern">{{'VALIDATION.TWO_DIGIT_DECIMAL'|translate}}</span>
      <span *ngIf="control.errors.validateMax">{{'VALIDATION.MAX_VALUE'|translate:control.errors.validateMax}}</span>
      <span *ngIf="control.errors.validateMin">{{'VALIDATION.MIN_VALUE'|translate:control.errors.validateMin}}</span>
    </div>
  </ng-container>
</ng-template>`;var ee="";var me=function(r,e,t,i){var n=arguments.length,a=n<3?e:i===null?i=Object.getOwnPropertyDescriptor(e,t):i,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(r,e,t,i);else for(var s=r.length-1;s>=0;s--)(o=r[s])&&(a=(n<3?o(a):n>3?o(e,t,a):o(e,t))||a);return n>3&&a&&Object.defineProperty(e,t,a),a},S=class extends R{formBuilder;sessionService;socialAreaService;languageService;identitySelectionService;modalService;visibleComponent=!1;upsertMode=!0;failedUsers;form;constructor(e,t,i,n,a,o){super(),this.formBuilder=e,this.sessionService=t,this.socialAreaService=i,this.languageService=n,this.identitySelectionService=a,this.modalService=o}onModalInitialized(){super.onModalInitialized(),this.createForm(),this.visibleComponent=!0}createForm(){this.form=this.formBuilder.group({amount:[null,[u.required,y.numeric({acceptValue:M.PositiveNumber,allowDecimal:!0}),u.pattern(this.languageService.getSeparator("decimal")==","?/^(\d+(\,\d{0,2})?|\,?\d{1,2})$/:/^(\d+(\.\d{0,2})?|\.?\d{1,2})$/),Z(9999.99),K(.01)]],increment:[!0],note:[null,u.maxLength(255)]})}onSaveClicked(e){this.showUserSelection()}getSessionForTransaction(e){return this.identitySelectionService.getSessionForTransaction(e)}showUserSelection(){this.modalService.open(j,{settings:{size:"xl"},props:{editable:!0,sessionFunction:this.getSessionForTransaction.bind(this),useCustomApply:!0}}).result.then(e=>{if(e){let t=D.getEmptyModel();t.note=this.form.value.name;let i=Number(this.form.get("amount").value.replace(",","."));this.form.get("increment").value==!1?t.amount=-Math.abs(i):t.amount=i;let n=P.getEmptyModel();n.note=t.note,n.amount=t.amount,this.socialAreaService.assignBalance(e.sessionId,n).subscribe(a=>{a&&a.failedUsers&&a.failedUsers.length>0?(this.failedUsers=a.failedUsers,this.upsertMode=!1):this.closeModal(t)})}}).catch(e=>{})}static ctorParameters=()=>[{type:U},{type:O},{type:v},{type:g},{type:z},{type:d}]};S=me([l({selector:"armon-soca-balance-upsert",template:J,standalone:!0,imports:[c,f,L,b,I,C,h,m],styles:[ee]})],S);var ae=ne(oe());var pe=function(r,e,t,i){var n=arguments.length,a=n<3?e:i===null?i=Object.getOwnPropertyDescriptor(e,t):i,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(r,e,t,i);else for(var s=r.length-1;s>=0;s--)(o=r[s])&&(a=(n<3?o(a):n>3?o(e,t,a):o(e,t))||a);return n>3&&a&&Object.defineProperty(e,t,a),a},te=class{router;route;authService;socialAreaService;languageService;routingService;modalService;translate;filter;balances;visibleComponent=!1;paginationResponse=new B;paginationRequest=new x;permissionSearchUserGroup;permissionSearchIdentity;permissionSearchOrganizationUnit;constructor(e,t,i,n,a,o,s,ie){this.router=e,this.route=t,this.authService=i,this.socialAreaService=n,this.languageService=a,this.routingService=o,this.modalService=s,this.translate=ie}ngOnInit(){this.permissionSearchUserGroup=this.authService.checkPermission(p.USERGROUP.getRead()),this.permissionSearchIdentity=this.authService.checkPermission(p.IDENTITY.getReadBasic()),this.permissionSearchOrganizationUnit=this.authService.checkPermission(p.ORGANIZATIONUNIT.getReadBasic()),this.filter=w.getEmptyModel(),this.visibleComponent=!0,this.getList()}ngOnDestroy(){}getList(){this.socialAreaService.getBalanceList(this.filter).subscribe(e=>{this.balances=e.items,this.paginationResponse=e.pagination})}onGetExcelClicked(e){this.socialAreaService.getBalanceListAsExcel(this.filter).subscribe(t=>{this.translate.get(["PAGES.SOCA_MANAGEMENT_BALANCE"]).subscribe(i=>{ae.default.saveAs(t,i["PAGES.SOCA_MANAGEMENT_BALANCE"]+" "+A.local().toLocaleString(A.DATETIME_MED)+".xlsx")})})}refreshList(e=!0){e&&(this.filter.pagination.skip=0),this.getList()}onFilterUpdated(e){this.refreshList()}onNewActionClicked(e){this.modalService.open(S,{settings:{size:"md",scrollable:!0}}).result.then(t=>{t&&this.getList()}).catch(t=>{})}pageChanged(e){this.filter.pagination.skip=e.skip,this.filter.pagination.take=e.take,this.refreshList(!1)}gotoUserUsageReport(e){this.routingService.gotoSocaUserUsageReport(e)}gotoUserTransactionReport(e){this.routingService.gotoSocaUserTransactionReport(e)}static ctorParameters=()=>[{type:_},{type:E},{type:F},{type:v},{type:g},{type:k},{type:d},{type:T}]};te=pe([l({selector:"armon-soca-balance-management",template:Q,standalone:!0,imports:[c,q,$,G,f,W,Y,X,h,V,N,m],styles:[H]})],te);export{te as SocaBalanceManagementComponent};
