public PhysicalPerson_AddEdit(PhysicalPersonViewModel PhysicalPersonViewModel, bool isCreateProcess, bool isPopup = false)
        {
            // Initialize service
            outputInvoiceService = DependencyResolver.Kernel.Get <IPhysicalPersonService>();

            InitializeComponent();

            this.DataContext = this;

            IsHeaderCreated = !isCreateProcess;

            CurrentPhysicalPerson = PhysicalPersonViewModel;
            IsCreateProcess       = isCreateProcess;
            IsPopup = isPopup;
        }
        public PhysicalPerson_Card_AddEdit(PhysicalPersonViewModel physicalPerson)
        {
            physicalPersonService     = DependencyResolver.Kernel.Get <IPhysicalPersonService>();
            physicalPersonNoteService = DependencyResolver.Kernel.Get <IPhysicalPersonCardService>();

            InitializeComponent();

            this.DataContext = this;

            CurrentPhysicalPerson                    = physicalPerson;
            CurrentPhysicalPersonCardForm            = new PhysicalPersonCardViewModel();
            CurrentPhysicalPersonCardForm.Identifier = Guid.NewGuid();
            CurrentPhysicalPersonCardForm.ItemStatus = ItemStatus.Added;

            Thread displayThread = new Thread(() => DisplayPhysicalPersonCardData());

            displayThread.IsBackground = true;
            displayThread.Start();

            btnAddNote.Focus();
        }
        //public PhysicalPersonListResponse GetUnSyncedItems(int companyId)
        //{
        //	PhysicalPersonListResponse response = new PhysicalPersonListResponse();
        //	List<PhysicalPersonViewModel> viewModels = new List<PhysicalPersonViewModel>();

        //	using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
        //	{
        //		db.Open();
        //		try
        //		{
        //			SqliteCommand selectCommand = new SqliteCommand(
        //				SqlCommandSelectPart +
        //				"FROM PhysicalPersons " +
        //				"WHERE CompanyId = @CompanyId AND IsSynced = 0 " +
        //				"ORDER BY Id DESC;", db);
        //			selectCommand.Parameters.AddWithValue("@CompanyId", companyId);

        //			SqliteDataReader query = selectCommand.ExecuteReader();

        //			while (query.Read())
        //			{
        //				int counter = 0;
        //				PhysicalPersonViewModel dbEntry = new PhysicalPersonViewModel();
        //				dbEntry.Id = SQLiteHelper.GetInt(query, ref counter);
        //				dbEntry.Identifier = SQLiteHelper.GetGuid(query, ref counter);
        //				dbEntry.Code = SQLiteHelper.GetString(query, ref counter);
        //				dbEntry.PhysicalPersonCode = SQLiteHelper.GetString(query, ref counter);
        //				dbEntry.Name = SQLiteHelper.GetString(query, ref counter);
        //				dbEntry.SurName = SQLiteHelper.GetString(query, ref counter);
        //				dbEntry.ConstructionSiteCode = SQLiteHelper.GetString(query, ref counter);
        //				dbEntry.ConstructionSiteName = SQLiteHelper.GetString(query, ref counter);

        //				dbEntry.DateOfBirth = SQLiteHelper.GetDateTime(query, ref counter);
        //				dbEntry.Gender = SQLiteHelper.GetInt(query, ref counter);
        //				dbEntry.Country = SQLiteHelper.GetCountry(query, ref counter);
        //				dbEntry.Region = SQLiteHelper.GetRegion(query, ref counter);
        //				dbEntry.Municipality = SQLiteHelper.GetMunicipality(query, ref counter);
        //				dbEntry.City = SQLiteHelper.GetCity(query, ref counter);
        //				dbEntry.Address = SQLiteHelper.GetString(query, ref counter);

        //				dbEntry.PassportCountry = SQLiteHelper.GetCountry(query, ref counter);
        //				dbEntry.PassportCity = SQLiteHelper.GetCity(query, ref counter);
        //				dbEntry.Passport = SQLiteHelper.GetString(query, ref counter);
        //				dbEntry.VisaFrom = SQLiteHelper.GetDateTime(query, ref counter);
        //				dbEntry.VisaTo = SQLiteHelper.GetDateTime(query, ref counter);
        //				dbEntry.ResidenceCountry = SQLiteHelper.GetCountry(query, ref counter);
        //				dbEntry.ResidenceCity = SQLiteHelper.GetCity(query, ref counter);
        //				dbEntry.ResidenceAddress = SQLiteHelper.GetString(query, ref counter);

        //				dbEntry.EmbassyDate = SQLiteHelper.GetDateTime(query, ref counter);
        //				dbEntry.VisaDate = SQLiteHelper.GetDateTimeNullable(query, ref counter);
        //				dbEntry.VisaValidFrom = SQLiteHelper.GetDateTimeNullable(query, ref counter);
        //				dbEntry.VisaValidTo = SQLiteHelper.GetDateTimeNullable(query, ref counter);
        //				dbEntry.WorkPermitFrom = SQLiteHelper.GetDateTime(query, ref counter);
        //				dbEntry.WorkPermitTo = SQLiteHelper.GetDateTime(query, ref counter);

        //				dbEntry.IsSynced = SQLiteHelper.GetBoolean(query, ref counter);
        //				dbEntry.UpdatedAt = SQLiteHelper.GetDateTime(query, ref counter);
        //				dbEntry.CreatedBy = SQLiteHelper.GetCreatedBy(query, ref counter);
        //				dbEntry.Company = SQLiteHelper.GetCompany(query, ref counter);
        //				viewModels.Add(dbEntry);
        //			}

        //		}
        //		catch (SqliteException error)
        //		{
        //			MainWindow.ErrorMessage = error.Message;
        //			response.Success = false;
        //			response.Message = error.Message;
        //			response.PhysicalPersons = new List<PhysicalPersonViewModel>();
        //			return response;
        //		}
        //		db.Close();
        //	}
        //	response.Success = true;
        //	response.PhysicalPersons = viewModels;
        //	return response;
        //}

        #endregion

        #region Sync

        public void Sync(IPhysicalPersonService physicalPersonService, Action <int, int> callback = null)
        {
            try
            {
                SyncPhysicalPersonRequest request = new SyncPhysicalPersonRequest();
                request.CompanyId     = MainWindow.CurrentCompanyId;
                request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId);

                int toSync      = 0;
                int syncedItems = 0;

                PhysicalPersonListResponse response = physicalPersonService.Sync(request);
                if (response.Success)
                {
                    toSync = response?.PhysicalPersons?.Count ?? 0;
                    var items = new List <PhysicalPersonViewModel>(response.PhysicalPersons);

                    using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
                    {
                        db.Open();
                        using (var transaction = db.BeginTransaction())
                        {
                            SqliteCommand deleteCommand = db.CreateCommand();
                            deleteCommand.CommandText = "DELETE FROM PhysicalPersons WHERE Identifier = @Identifier";

                            SqliteCommand insertCommand = db.CreateCommand();
                            insertCommand.CommandText = SqlCommandInsertPart;

                            foreach (var item in items)
                            {
                                deleteCommand.Parameters.AddWithValue("@Identifier", item.Identifier);
                                deleteCommand.ExecuteNonQuery();
                                deleteCommand.Parameters.Clear();

                                if (item.IsActive)
                                {
                                    item.IsSynced = true;

                                    insertCommand = AddCreateParameters(insertCommand, item);
                                    insertCommand.ExecuteNonQuery();
                                    insertCommand.Parameters.Clear();

                                    syncedItems++;
                                    callback?.Invoke(syncedItems, toSync);
                                }
                            }

                            transaction.Commit();
                        }
                        db.Close();
                    }
                }
                else
                {
                    throw new Exception(response.Message);
                }
            }
            catch (Exception ex)
            {
                MainWindow.ErrorMessage = ex.Message;
            }
        }
 public PhysicalPersonController(IServiceProvider provider)
 {
     PhysicalPersonService = provider.GetRequiredService <IPhysicalPersonService>();
 }
 public PhysicalPersonController(IPhysicalPersonService personService)
 {
     _personService = personService;
 }
        public Home()
        {
            businessPartnerService            = DependencyResolver.Kernel.Get <IBusinessPartnerService>();
            businessPartnerTypeService        = DependencyResolver.Kernel.Get <IBusinessPartnerTypeService>();
            businessPartnerBankService        = DependencyResolver.Kernel.Get <IBusinessPartnerBankService>();
            businessPartnerDocumentService    = DependencyResolver.Kernel.Get <IBusinessPartnerDocumentService>();
            businessPartnerInstitutionService = DependencyResolver.Kernel.Get <IBusinessPartnerInstitutionService>();
            businessPartnerLocationService    = DependencyResolver.Kernel.Get <IBusinessPartnerLocationService>();
            businessPartnerNoteService        = DependencyResolver.Kernel.Get <IBusinessPartnerNoteService>();
            //businessPartnerOrganizationUnitService = DependencyResolver.Kernel.Get<IBusinessPartnerOrganizationUnitService>();
            businessPartnerPhoneService = DependencyResolver.Kernel.Get <IBusinessPartnerPhoneService>();


            employeeService           = DependencyResolver.Kernel.Get <IEmployeeService>();
            employeeProfessionService = DependencyResolver.Kernel.Get <IEmployeeProfessionService>();
            employeeNoteService       = DependencyResolver.Kernel.Get <IEmployeeNoteService>();
            employeeLicenceService    = DependencyResolver.Kernel.Get <IEmployeeLicenceService>();
            employeeItemService       = DependencyResolver.Kernel.Get <IEmployeeItemService>();
            employeeDocumentService   = DependencyResolver.Kernel.Get <IEmployeeDocumentService>();
            employeeCardService       = DependencyResolver.Kernel.Get <IEmployeeCardService>();

            licenceTypeService  = DependencyResolver.Kernel.Get <ILicenceTypeService>();
            familyMemberService = DependencyResolver.Kernel.Get <IFamilyMemberService>();

            physicalPersonService           = DependencyResolver.Kernel.Get <IPhysicalPersonService>();
            physicalPersonProfessionService = DependencyResolver.Kernel.Get <IPhysicalPersonProfessionService>();
            physicalPersonNoteService       = DependencyResolver.Kernel.Get <IPhysicalPersonNoteService>();
            physicalPersonLicenceService    = DependencyResolver.Kernel.Get <IPhysicalPersonLicenceService>();
            physicalPersonItemService       = DependencyResolver.Kernel.Get <IPhysicalPersonItemService>();
            physicalPersonDocumentService   = DependencyResolver.Kernel.Get <IPhysicalPersonDocumentService>();
            physicalPersonCardService       = DependencyResolver.Kernel.Get <IPhysicalPersonCardService>();


            outputInvoiceService = DependencyResolver.Kernel.Get <IOutputInvoiceService>();
            inputInvoiceService  = DependencyResolver.Kernel.Get <IInputInvoiceService>();

            countryService      = DependencyResolver.Kernel.Get <ICountryService>();
            regionService       = DependencyResolver.Kernel.Get <IRegionService>();
            municipalityService = DependencyResolver.Kernel.Get <IMunicipalityService>();
            cityService         = DependencyResolver.Kernel.Get <ICityService>();

            sectorService     = DependencyResolver.Kernel.Get <ISectorService>();
            professionService = DependencyResolver.Kernel.Get <IProfessionService>();
            bankService       = DependencyResolver.Kernel.Get <IBankService>();
            agencyService     = DependencyResolver.Kernel.Get <IAgencyService>();

            constructionSiteService            = DependencyResolver.Kernel.Get <IConstructionSiteService>();
            constructionSiteDocumentService    = DependencyResolver.Kernel.Get <IConstructionSiteDocumentService>();
            constructionSiteCalculationService = DependencyResolver.Kernel.Get <IConstructionSiteCalculationService>();
            constructionSiteNoteService        = DependencyResolver.Kernel.Get <IConstructionSiteNoteService>();


            //employeeByBusinessPartnerService = DependencyResolver.Kernel.Get<IEmployeeByBusinessPartnerService>(); //radnici po firmama?
            //employeeByConstructionSiteService = DependencyResolver.Kernel.Get<IEmployeeByConstructionSiteService>(); // radnici po gradilistu
            //businessPartnerByConstructionSiteService = DependencyResolver.Kernel.Get<IBusinessPartnerByConstructionSiteService>(); //firme po gradilistu

            taxAdministrationService = DependencyResolver.Kernel.Get <ITaxAdministrationService>();

            limitationService      = DependencyResolver.Kernel.Get <ILimitationService>();
            userService            = DependencyResolver.Kernel.Get <IUserService>();
            vatService             = DependencyResolver.Kernel.Get <IVatService>();
            discountService        = DependencyResolver.Kernel.Get <IDiscountService>();
            serviceDeliveryService = DependencyResolver.Kernel.Get <IServiceDeliveryService>();
            statusService          = DependencyResolver.Kernel.Get <IStatusService>();
            shipmentService        = DependencyResolver.Kernel.Get <IShipmentService>();

            toDoService = DependencyResolver.Kernel.Get <IToDoService>();

            phonebookService  = DependencyResolver.Kernel.Get <IPhonebookService>();
            callCentarService = DependencyResolver.Kernel.Get <ICallCentarService>();

            employeeByConstructionSiteService        = DependencyResolver.Kernel.Get <IEmployeeByConstructionSiteService>();
            businessPartnerByConstructionSiteService = DependencyResolver.Kernel.Get <IBusinessPartnerByConstructionSiteService>();
            employeeByBusinessPartnerService         = DependencyResolver.Kernel.Get <IEmployeeByBusinessPartnerService>();

            documentFolderService = DependencyResolver.Kernel.Get <IDocumentFolderService>();
            documentFileService   = DependencyResolver.Kernel.Get <IDocumentFileService>();

            InitializeComponent();

            this.DataContext = this;

            var resp = new CompanyUserSQLiteRepository().GetCompanyUser(MainWindow.CurrentCompanyId, MainWindow.CurrentUser?.Identifier ?? Guid.Empty);

            if (resp.Success)
            {
                var userRoles = resp.CompanyUser?.UserRoles ?? new List <UserRoleViewModel>();
                if (userRoles.Any(x => x.Name == "CallCentar") || userRoles.Any(x => x.Name == "Admin"))
                {
                    CallCentarList.Visibility = System.Windows.Visibility.Visible;
                }
                else
                {
                    CallCentarList.Visibility = System.Windows.Visibility.Collapsed;
                }
            }
        }