From df6f21f74b62b42f53dfbe542926aca7ec228d1b Mon Sep 17 00:00:00 2001 From: mostafa7171 Date: Tue, 27 Jan 2026 14:30:24 +0330 Subject: [PATCH] update for wage --- panel/KillHouse/helpers.py | 219 +++ panel/ProvinceOperator/serializers.py | 1755 ++++++++++++------------- 2 files changed, 1048 insertions(+), 926 deletions(-) diff --git a/panel/KillHouse/helpers.py b/panel/KillHouse/helpers.py index 161bfd7..6eed02f 100644 --- a/panel/KillHouse/helpers.py +++ b/panel/KillHouse/helpers.py @@ -901,6 +901,225 @@ def get_kill_houses_out_buying_info(kill_houses, date1=None, date2=None): final_out_live_buying_province_carcasses_weight +=total_out_live_buying_province_carcasses_weight print(final_out_live_buying_province_carcasses_weight) return final_out_live_buying_province_carcasses_weight +def get_total_wage_info(kill_house): + total_wage = 0 + total_paid_wage = 0 + off = 0 + total_unpaid_wage = 0 + province_kill_requests_total_wage = 0 + province_kill_requests_total_weight = 0 + free_bars_live_total_wage = 0 + free_bars_live_total_weight = 0 + free_bars_carcases_total_wage = 0 + free_bars_carcases_total_weight = 0 + free_bars_out_province_carcases_total_wage = 0 + free_bars_out_province_carcases_total_weight = 0 + total_province_live_weight = 0 + total_province_carcasses_weight = 0 + province_live_wage_amount = 0 + free_buying_live_weight_amount = 0 + free_buying_carcesses_weight_amount = 0 + free_sell_carcesses_weight_amount = 0 + return_total_province_live_weight = 0 + total_return_pure_province_carcasses_price = 0 + total_pure_province_carcasses_price = 0 + return_total_pure_province_carcasses_price = 0 + total_out_selling_province_carcasses_price = 0 + difference_requests_price = 0 + + before_total_out_live_buying_province_carcasses_price = 0 + total_out_live_buying_province_carcasses_price = 0 + total_out_carcasses_buying_province_carcasses_price = 0 + + guilds_difference_requests_price = 0 + other_difference_requests_price = 0 + guild_return_province_kill_request_wage = 0 + other_return_province_kill_request_wage = 0 + + before_total_out_live_buying_province_carcasses_price = 0 + total_wage_type = WageType.objects.filter(trash=False) + free_buying_live_weight_wage_type = total_wage_type.filter(en_name='live-buy', trash=False).first() + free_buying_live_weight_wage_type_amount = free_buying_live_weight_wage_type.amount if free_buying_live_weight_wage_type.status == True else 0 + + finance_info = get_finance_info(kill_house) + if kill_house.killer and kill_house.type == 'public': + + slaughter_transactions = InternalTransaction.objects.filter( + kill_house=kill_house, parent_kill_house=kill_house, status='completed', + trash=False) + else: + slaughter_transactions = InternalTransaction.objects.filter( + Q(kill_house=kill_house) | Q(parent_kill_house=kill_house), status='completed', + trash=False) + + + total_paid_wage += slaughter_transactions.aggregate(total=Sum('amount'))[ + 'total'] or 0 + + total_pure_province_carcasses_price = finance_info['total_pure_province_carcasses_price'] + return_total_pure_province_carcasses_price = finance_info['total_return_pure_province_carcasses_price'] + total_out_selling_province_carcasses_price = finance_info['total_out_selling_province_carcasses_price'] + difference_requests_price = finance_info['difference_requests_price'] + + if new_out_selling_count_wage: + total_out_live_buying_province_carcasses_price = int( + (finance_info[ + 'before_total_out_live_buying_province_carcasses_weight'] * before_out_buying_count_wage_amount) + ( + finance_info[ + 'after_total_out_live_buying_province_carcasses_weight'] * free_buying_live_weight_wage_type_amount)) + + before_total_out_live_buying_province_carcasses_price = finance_info[ + 'before_total_out_live_buying_province_carcasses_weight'] * before_out_buying_count_wage_amount + else: + total_out_live_buying_province_carcasses_price = finance_info[ + 'total_out_live_buying_province_carcasses_price'] + total_out_carcasses_buying_province_carcasses_price = finance_info[ + 'total_out_carcasses_buying_province_carcasses_price'] + + percentages_wage_type = PercentageOfWageType.objects.filter(trash=False) + union_province_kill_request_percent = percentages_wage_type.filter( + wage_type__en_name='province-kill-request', share_type__en_name='union').first().percent / 100 + company_province_kill_request_percent = percentages_wage_type.filter( + wage_type__en_name='province-kill-request', share_type__en_name='company').first().percent / 100 + guilds_province_kill_request_percent = percentages_wage_type.filter( + wage_type__en_name='province-kill-request', share_type__en_name='guilds').first().percent / 100 + other_province_kill_request_percent = percentages_wage_type.filter( + wage_type__en_name='province-kill-request', share_type__en_name='other').first().percent / 100 + + union_free_buying_live_percent = percentages_wage_type.filter(wage_type__en_name='live-buy', + share_type__en_name='union').first().percent / 100 + union_free_buying_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-buy', + share_type__en_name='union').first().percent / 100 + company_free_buying_live_percent = percentages_wage_type.filter(wage_type__en_name='live-buy', + share_type__en_name='company').first().percent / 100 + company_free_buying_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-buy', + share_type__en_name='company').first().percent / 100 + guilds_free_buying_live_percent = percentages_wage_type.filter(wage_type__en_name='live-buy', + share_type__en_name='guilds').first().percent / 100 + guilds_free_buying_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-buy', + share_type__en_name='guilds').first().percent / 100 + other_free_buying_live_percent = percentages_wage_type.filter(wage_type__en_name='live-buy', + share_type__en_name='other').first().percent / 100 + other_free_buying_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-buy', + share_type__en_name='other').first().percent / 100 + + union_free_sell_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-sell', + share_type__en_name='union').first().percent / 100 + company_free_sell_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-sell', + share_type__en_name='company').first().percent / 100 + guilds_free_sell_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-sell', + share_type__en_name='guilds').first().percent / 100 + other_free_sell_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-sell', + share_type__en_name='other').first().percent / 100 + + guilds_difference_requests_price = difference_requests_price * guilds_province_kill_request_percent + other_difference_requests_price = difference_requests_price * other_province_kill_request_percent + guild_return_province_kill_request_wage = return_total_pure_province_carcasses_price * guilds_province_kill_request_percent + other_return_province_kill_request_wage = return_total_pure_province_carcasses_price * other_province_kill_request_percent + + union_province_kill_request_wage = total_pure_province_carcasses_price * union_province_kill_request_percent + return_union_province_kill_request_wage = return_total_pure_province_carcasses_price * union_province_kill_request_percent + union_free_buying_live_wage = ( + total_out_live_buying_province_carcasses_price - before_total_out_live_buying_province_carcasses_price) * union_free_buying_live_percent + union_free_buying_carcasses_wage = total_out_carcasses_buying_province_carcasses_price * union_free_buying_carcasses_percent + union_free_sell_carcasses_wage = total_out_selling_province_carcasses_price * union_free_sell_carcasses_percent + union_total_wage = union_province_kill_request_wage + union_free_buying_live_wage + union_free_buying_carcasses_wage + union_free_sell_carcasses_wage + return_union_province_kill_request_wage + union_total_paid_wage = slaughter_transactions.aggregate(total=Sum('union_share'))['total'] or 0 + union_total_unpaid_wage = union_total_wage - union_total_paid_wage + company_province_kill_request_wage = ( + total_pure_province_carcasses_price * company_province_kill_request_percent) + ( + guilds_difference_requests_price + other_difference_requests_price) + return_company_province_kill_request_wage = ( + return_total_pure_province_carcasses_price * company_province_kill_request_percent) + ( + guild_return_province_kill_request_wage + other_return_province_kill_request_wage) + company_free_buying_live_wage = (( + total_out_live_buying_province_carcasses_price - before_total_out_live_buying_province_carcasses_price) * company_free_buying_live_percent) + before_total_out_live_buying_province_carcasses_price + company_free_buying_carcasses_wage = total_out_carcasses_buying_province_carcasses_price * company_free_buying_carcasses_percent + company_free_sell_carcasses_wage = total_out_selling_province_carcasses_price * company_free_sell_carcasses_percent + company_total_wage = company_province_kill_request_wage + company_free_buying_live_wage + company_free_buying_carcasses_wage + company_free_sell_carcasses_wage + return_company_province_kill_request_wage + company_total_paid_wage = slaughter_transactions.aggregate(total=Sum('company_share'))['total'] or 0 + company_total_unpaid_wage = company_total_wage - company_total_paid_wage + + guilds_province_kill_request_wage = ( + total_pure_province_carcasses_price * guilds_province_kill_request_percent) - guilds_difference_requests_price + return_guilds_province_kill_request_wage = 0 + guilds_free_buying_live_wage = ( + total_out_live_buying_province_carcasses_price - before_total_out_live_buying_province_carcasses_price) * guilds_free_buying_live_percent + guilds_free_buying_carcasses_wage = total_out_carcasses_buying_province_carcasses_price * guilds_free_buying_carcasses_percent + guilds_free_sell_carcasses_wage = total_out_selling_province_carcasses_price * guilds_free_sell_carcasses_percent + guilds_total_wage = guilds_province_kill_request_wage + guilds_free_buying_live_wage + guilds_free_buying_carcasses_wage + guilds_free_sell_carcasses_wage + guilds_total_paid_wage = slaughter_transactions.aggregate(total=Sum('guilds_share'))['total'] or 0 + guilds_total_unpaid_wage = guilds_total_wage - guilds_total_paid_wage + + other_province_kill_request_wage = ( + total_pure_province_carcasses_price * other_province_kill_request_percent) - other_difference_requests_price + return_other_province_kill_request_wage = 0 + other_free_buying_live_wage = ( + total_out_live_buying_province_carcasses_price - before_total_out_live_buying_province_carcasses_price) * other_free_buying_live_percent + other_free_buying_carcasses_wage = total_out_carcasses_buying_province_carcasses_price * other_free_buying_carcasses_percent + other_free_sell_carcasses_wage = total_out_selling_province_carcasses_price * other_free_sell_carcasses_percent + other_total_wage = other_province_kill_request_wage + other_free_buying_live_wage + other_free_buying_carcasses_wage + other_free_sell_carcasses_wage + other_total_paid_wage = slaughter_transactions.aggregate(total=Sum('other_share'))['total'] or 0 + other_total_unpaid_wage = other_total_wage - other_total_paid_wage + + result = { + "wage_counting_type": wage_counting_type, + "total_wage": finance_info['total_price'], + "total_paid_wage": total_paid_wage, + "off": kill_house.off, + "total_unpaid_wage": finance_info['total_price'] - (total_paid_wage + kill_house.off), + "province_kill_requests_total_wage": finance_info['total_pure_province_carcasses_price'], + "province_kill_requests_total_weight": finance_info['total_pure_province_carcasses_weight'], + "free_bars_live_total_wage": finance_info['total_out_live_buying_province_carcasses_price'], + "free_bars_live_total_weight": finance_info['total_out_live_buying_province_carcasses_weight'], + "free_bars_carcases_total_wage": finance_info['total_out_carcasses_buying_province_carcasses_price'], + "free_bars_carcases_total_weight": finance_info['total_out_carcasses_buying_province_carcasses_weight'], + "free_bars_out_province_carcases_total_wage": finance_info['total_out_selling_province_carcasses_price'], + "free_bars_out_province_carcases_total_weight": finance_info['total_out_selling_province_carcasses_weight'], + "total_province_live_weight": finance_info['total_province_live_weight'], + "total_province_carcasses_weight": finance_info['total_province_carcasses_weight'], + "province_live_wage_amount": finance_info['province_live_wage_amount'], + "free_buying_live_weight_amount": finance_info['free_buying_live_weight_amount'], + "free_buying_carcesses_weight_amount": finance_info['free_buying_carcesses_weight_amount'], + "free_sell_carcesses_weight_amount": finance_info['free_sell_carcesses_weight_amount'], + "extra_company_amount":finance_info['extra_company_amount'], + "return_total_province_live_weight": finance_info['return_total_province_live_weight'], + "total_return_pure_province_carcasses_price": finance_info['total_return_pure_province_carcasses_price'], + "union_province_kill_request_wage": union_province_kill_request_wage, + "return_union_province_kill_request_wage": return_union_province_kill_request_wage, + "union_free_buying_live_wage": union_free_buying_live_wage, + "union_free_buying_carcasses_wage": union_free_buying_carcasses_wage, + "union_free_sell_carcasses_wage": union_free_sell_carcasses_wage, + "union_total_wage": union_total_wage, + "union_total_paid_wage": union_total_paid_wage, + "union_total_unpaid_wage": union_total_unpaid_wage, + "company_province_kill_request_wage": company_province_kill_request_wage, + "return_company_province_kill_request_wage": return_company_province_kill_request_wage, + "company_free_buying_live_wage": company_free_buying_live_wage, + "company_free_buying_carcasses_wage": company_free_buying_carcasses_wage, + "company_free_sell_carcasses_wage": company_free_sell_carcasses_wage, + "company_total_wage": company_total_wage, + "company_total_paid_wage": company_total_paid_wage, + "company_total_unpaid_wage": company_total_unpaid_wage, + "guilds_province_kill_request_wage": guilds_province_kill_request_wage, + "return_guilds_province_kill_request_wage": return_guilds_province_kill_request_wage, + "guilds_free_buying_live_wage": guilds_free_buying_live_wage, + "guilds_free_buying_carcasses_wage": guilds_free_buying_carcasses_wage, + "guilds_free_sell_carcasses_wage": guilds_free_sell_carcasses_wage, + "guilds_total_wage": guilds_total_wage, + "guilds_total_paid_wage": guilds_total_paid_wage, + "guilds_total_unpaid_wage": guilds_total_unpaid_wage, + "other_province_kill_request_wage": other_province_kill_request_wage, + "return_other_province_kill_request_wage": return_other_province_kill_request_wage, + "other_free_buying_live_wage": other_free_buying_live_wage, + "other_free_buying_carcasses_wage": other_free_buying_carcasses_wage, + "other_free_sell_carcasses_wage": other_free_sell_carcasses_wage, + "other_total_wage": other_total_wage, + "other_total_paid_wage": other_total_paid_wage, + "other_total_unpaid_wage": other_total_unpaid_wage, + } + + return result def get_kill_house_finance_info(kill_house, date1=None, date2=None): diff --git a/panel/ProvinceOperator/serializers.py b/panel/ProvinceOperator/serializers.py index 129cf18..5c1d1d9 100644 --- a/panel/ProvinceOperator/serializers.py +++ b/panel/ProvinceOperator/serializers.py @@ -22,7 +22,7 @@ from deposit_percent import wage_percent, carcases_sell from general_urls import base_url_for_sms_report from panel.CityOperator.serializers import CityOperatorForSubSectorTransactionsSerializer from panel.KillHouse.helpers import get_finance_info, get_difference_carcasses_weight, get_new_wage_for_free_buying, \ - get_kill_houses_out_buying_info + get_kill_houses_out_buying_info, get_kill_house_finance_info, get_total_wage_info from panel.KillHouse.serializers import VetSerializer, ProvinceKillRequestSerializer, \ KillHouseAssignmentInformationSerializer, KillHouseSerializer, KillHouseDailyQuotaSerializer, \ ProvinceKillRequestForAutoAllocationSerializer, KillHouseWareHouseSerializer, KillHouseForProvinceSerializer, \ @@ -78,7 +78,7 @@ from panel.models import ( GuildsGeneralConfigs, StewardAppLogin, StewardRequest, RestrictionCarcassDistribution, AllowRegisterCodeForKillHouseFreeSaleBarInformation, AllowRegisterCodeForStewardFreeSaleBarInformation, LimitationForDirectPurchaseAndBarInformation, WarehouseArchive, SmsRecipient, MarketDailyLimitation, - HatchingArchivePercent, Representative, POSAccessLevel, DispenserInformation + HatchingArchivePercent, Representative, POSAccessLevel, DispenserInformation, KillHousePercentage ) from panel.poultry.helpers import market_daily_limitation_info from panel.poultry.serializers import PoultryRequestSerializer, PoultrySerializer, \ @@ -3862,695 +3862,6 @@ class PoultryOutRequestInternalTransactionSerializer(serializers.ModelSerializer # } -class TotalWageInformationSerializer(serializers.ModelSerializer): - wage_info = serializers.SerializerMethodField('get_wage_info') - - class Meta: - model = TotalWageInformation - fields = ['key', 'wage_info'] - - def get_wage_info(self, obj): - before_total_out_live_buying_province_carcasses_weight = 0 - after_total_out_live_buying_province_carcasses_weight = 0 - before_new_out_selling = 0 - after_new_out_selling = 0 - company_before_total_out_live_buying_province_carcasses_price = 0 - before_total_out_live_buying_province_carcasses_price = 0 - company_before_total_out_live_buying_province_carcasses_weight = 0 - extra_company_amount = 0 - total_weight = 0 - total_wage = 0 - total_paid_wage = 0 - shares_list = [] - total_unpaid_wage = 0 - union_total_weight = 0 - union_total_wage = 0 - union_total_paid_wage = 0 - union_total_unpaid_wage = 0 - union_province_kill_request_total_wage = 0 - freezing_union_province_kill_request_total_wage = 0 - union_kill_house_free_live_bar_total_wage = 0 - union_kill_house_free_carcases_bar_total_wage = 0 - union_chain_allocation_total_wage = 0 - union_province_kill_request_total_weight = 0 - freezing_union_province_kill_request_total_weight = 0 - union_kill_house_free_live_bar_total_weight = 0 - union_kill_house_free_carcases_bar_total_weight = 0 - union_chain_allocation_total_weight = 0 - - company_total_weight = 0 - company_total_wage = 0 - company_total_paid_wage = 0 - company_total_unpaid_wage = 0 - company_province_kill_request_total_wage = 0 - freezing_company_province_kill_request_total_wage = 0 - company_kill_house_free_live_bar_total_wage = 0 - company_kill_house_free_carcases_bar_total_wage = 0 - company_chain_allocation_total_wage = 0 - company_province_kill_request_total_weight = 0 - freezing_company_province_kill_request_total_weight = 0 - company_kill_house_free_live_bar_total_weight = 0 - company_kill_house_free_carcases_bar_total_weight = 0 - company_chain_allocation_total_weight = 0 - - guilds_total_weight = 0 - guilds_total_wage = 0 - guilds_total_paid_wage = 0 - guilds_total_unpaid_wage = 0 - guilds_province_kill_request_total_wage = 0 - freezing_guilds_province_kill_request_total_wage = 0 - guilds_kill_house_free_live_bar_total_wage = 0 - guilds_kill_house_free_carcases_bar_total_wage = 0 - guilds_chain_allocation_total_wage = 0 - guilds_province_kill_request_total_weight = 0 - freezing_guilds_province_kill_request_total_weight = 0 - guilds_kill_house_free_live_bar_total_weight = 0 - guilds_kill_house_free_carcases_bar_total_weight = 0 - guilds_chain_allocation_total_weight = 0 - - other_total_weight = 0 - other_total_wage = 0 - other_total_paid_wage = 0 - other_total_unpaid_wage = 0 - other_province_kill_request_total_wage = 0 - freezing_other_province_kill_request_total_wage = 0 - other_kill_house_free_live_bar_total_wage = 0 - other_kill_house_free_carcases_bar_total_wage = 0 - other_chain_allocation_total_wage = 0 - other_province_kill_request_total_weight = 0 - freezing_other_province_kill_request_total_weight = 0 - other_kill_house_free_live_bar_total_weight = 0 - other_kill_house_free_carcases_bar_total_weight = 0 - other_chain_allocation_total_weight = 0 - - province_kill_request_total_wage = 0 - province_kill_request_total_weight = 0 - freezing_province_kill_requests_total_wage = 0 - freezing_province_kill_requests_total_weight = 0 - chain_total_wage = 0 - chain_total_weight = 0 - free_bars_live_total_wage = 0 - free_bars_live_total_weight = 0 - free_bars_carcases_total_wage = 0 - free_bars_carcases_total_weight = 0 - real_free_sale_wage = 0 - union_real_free_sale_wage = 0 - company_real_free_sale_wage = 0 - guilds_real_free_sale_wage = 0 - other_real_free_sale_wage = 0 - total_check_wage = 0 - union_wage_percent = 0 - company_wage_percent = 0 - guilds_wage_percent = 0 - other_wage_percent = 0 - date1 = None - date2 = None - role = None - if self.context: - role = self.context.get('request').GET.get('role') - if self.context.get('request').GET.get('date1'): - date1 = datetime.strptime(str(self.context.get('request').GET['date1']), - '%Y-%m-%d').date() - date2 = datetime.strptime(str(self.context.get('request').GET['date2']), - '%Y-%m-%d').date() - - wage_type = WageType.objects.filter(en_name='province-kill-request').first() - total_check_wage = wage_type.amount - percentages_wage_type = PercentageOfWageType.objects.filter(wage_type=wage_type, percent__gt=0, trash=False) - for percentage_wage_type in percentages_wage_type: - if percentage_wage_type.share_type.en_name == 'union': - union_wage_percent = percentage_wage_type.percent / 100 - elif percentage_wage_type.share_type.en_name == 'company': - company_wage_percent = percentage_wage_type.percent / 100 - - elif percentage_wage_type.share_type.en_name == 'guilds': - guilds_wage_percent = percentage_wage_type.percent / 100 - elif percentage_wage_type.share_type.en_name in ['city', 'wallet']: - pass - else: - other_wage_percent = percentage_wage_type.percent / 100 - total_wage_type = WageType.objects.filter(trash=False) - province_live_wage_amount = total_wage_type.filter(en_name='province-kill-request', trash=False).first().amount - free_buying_live_weight_amount = total_wage_type.filter(en_name='live-buy', trash=False).first().amount - free_buying_carcesses_weight_amount = total_wage_type.filter(en_name='carcasse-buy', trash=False).first().amount - free_sell_carcesses_weight_amount = total_wage_type.filter(en_name='carcasse-sell', trash=False).first().amount - out_province_poultry_request_wage_amount = total_wage_type.filter(en_name='poultry-sell-out-province', - trash=False).first().amount - - if role == 'KillHouse': - try: - user = SystemUserProfile.objects.get(user=self.context.get('request').user) - except: - user = SystemUserProfile.objects.get(key=self.context.get('request').GET['key']) - kill_house = KillHouse.objects.filter(kill_house_operator__user=user, trash=False).first() - # if date1: - # finance_info = get_finance_info(kill_house, date1, date2) - # slaughter_transactions = InternalTransaction.objects.filter( - # Q(kill_house=kill_house) | Q(parent_kill_house=kill_house), date__date__gte=date1, - # date__date__lte=date2, status='completed', - # trash=False) - # - # else: - # finance_info = get_finance_info(kill_house) - # slaughter_transactions = InternalTransaction.objects.filter( - # Q(kill_house=kill_house) | Q(parent_kill_house=kill_house), status='completed', - # trash=False) - if date1: - finance_info = get_finance_info(kill_house, date1, date2) - if kill_house.killer and kill_house.type == 'public': - slaughter_transactions = InternalTransaction.objects.filter( - kill_house=kill_house,parent_kill_house=kill_house, date__date__gte=date1, - date__date__lte=date2, status='completed', - trash=False) - else: - slaughter_transactions = InternalTransaction.objects.filter( - Q(kill_house=kill_house) | Q(parent_kill_house=kill_house), date__date__gte=date1, - date__date__lte=date2, status='completed', - trash=False) - - else: - finance_info = get_finance_info(kill_house) - if kill_house.killer and kill_house.type == 'public': - - slaughter_transactions = InternalTransaction.objects.filter( - kill_house=kill_house,parent_kill_house=kill_house, status='completed', - trash=False) - else: - slaughter_transactions = InternalTransaction.objects.filter( - Q(kill_house=kill_house) | Q(parent_kill_house=kill_house), status='completed', - trash=False) - - total_paid_wage += slaughter_transactions.aggregate(total=Sum('amount'))[ - 'total'] or 0 - - return { - "wage_counting_type": wage_counting_type, - "total_wage": finance_info['total_price'], - "total_paid_wage": total_paid_wage, - "off": kill_house.off, - "total_unpaid_wage": finance_info['total_price'] - (total_paid_wage + kill_house.off), - "province_kill_requests_total_wage": finance_info['total_pure_province_carcasses_price'], - "province_kill_requests_total_weight": finance_info['total_pure_province_carcasses_weight'], - "free_bars_live_total_wage": finance_info['total_out_live_buying_province_carcasses_price'], - "free_bars_live_total_weight": finance_info['total_out_live_buying_province_carcasses_weight'], - "free_bars_carcases_total_wage": finance_info['total_out_carcasses_buying_province_carcasses_price'], - "free_bars_carcases_total_weight": finance_info['total_out_carcasses_buying_province_carcasses_weight'], - "free_bars_out_province_carcases_total_wage": finance_info[ - 'total_out_selling_province_carcasses_price'], - "free_bars_out_province_carcases_total_weight": finance_info[ - 'total_out_selling_province_carcasses_weight'], - "total_province_live_weight": finance_info['total_province_live_weight'], - "total_province_carcasses_weight": finance_info['total_province_carcasses_weight'], - "province_live_wage_amount": province_live_wage_amount, - "free_buying_live_weight_amount": free_buying_live_weight_amount, - "free_buying_carcesses_weight_amount": free_buying_carcesses_weight_amount, - "free_sell_carcesses_weight_amount": free_sell_carcesses_weight_amount, - "finance_info": finance_info, - "return_total_province_live_weight": finance_info['return_total_province_live_weight'], - "total_return_pure_province_carcasses_price": finance_info[ - 'total_return_pure_province_carcasses_price'], - } - - elif role == 'ChainCompany': - try: - user = SystemUserProfile.objects.get(user=self.context.get('request').user) - except: - user = SystemUserProfile.objects.get(key=self.context.get('request').GET['key']) - chain_company = ChainCompany.objects.get(user=user, trash=False) - chain_allocations = ChainAllocation.objects.filter(chain_company=chain_company, state='accepted', - trash=False) - chain_allocations_total_wage = chain_allocations.aggregate(total=Sum('total_wage_amount'))[ - 'total'] or 0 - total_wage += chain_allocations_total_wage - chain_allocations_total_weight = chain_allocations.aggregate(total=Sum('weight'))[ - 'total'] or 0 - total_weight += chain_allocations_total_weight - - chain_company_transactions = InternalTransaction.objects.filter(chain_company=chain_company, - status='completed', trash=False) - total_paid_wage += chain_company_transactions.aggregate(total=Sum('amount'))[ - 'total'] or 0 - - return { - "total_weight": total_weight, - "total_wage": total_wage, - "chain_allocations_total_wage": chain_allocations_total_wage, - "chain_allocations_total_weight": chain_allocations_total_weight, - "total_paid_wage": total_paid_wage, - "total_unpaid_wage": total_wage - total_paid_wage - } - - - - - else: - kill_houses = KillHouse.objects.filter(out_province=False, trash=False).order_by('id') - if date1: - - province_kill_requests = ProvinceKillRequest.objects.filter(killhouse_user__in=kill_houses, trash=False, - archive_wage=False, - return_to_province=False, - state__in=('pending', 'accepted'), - kill_request__recive_date__date__gte=date1, - kill_request__recive_date__date__lte=date2, - first_car_allocated_quantity=0).order_by( - 'id') - return_province_kill_requests = ProvinceKillRequest.objects.filter(killhouse_user__in=kill_houses, - trash=True, return_trash=True, - archive_wage=False, - return_to_province=False, - state__in=('pending', 'accepted'), - kill_request__recive_date__date__gte=date1, - kill_request__recive_date__date__lte=date2, - first_car_allocated_quantity=0).order_by( - 'id') - kill_house_requests = KillHouseRequest.objects.filter( - Q(Q(killhouse_user__in=kill_houses) & Q(killer__in=kill_houses)) | Q( - Q(killhouse_user__in=kill_houses) & Q(killer__isnull=True)) | Q( - Q(killhouse_user__in=kill_houses) | Q(killer__in=kill_houses)), archive_wage=False, - kill_request__recive_date__date__gte=date1, kill_request__recive_date__date__lte=date2, - trash=False, calculate_status=True - ) - return_kill_house_requests = KillHouseRequest.objects.filter( - Q(Q(killhouse_user__in=kill_houses) & Q(killer__in=kill_houses)) | Q( - Q(killhouse_user__in=kill_houses) & Q(killer__isnull=True)) | Q( - Q(killhouse_user__in=kill_houses) | Q(killer__in=kill_houses)), archive_wage=False, - kill_request__recive_date__date__gte=date1, kill_request__recive_date__date__lte=date2, - trash=True, return_trash=True, calculate_status=True - ) - kill_house_free_bar_info = KillHouseFreeBarInformation.objects.filter(kill_house__in=kill_houses, - archive_wage=False, - calculate_status=True, - create_date__date__gte=date1, - create_date__date__lte=date2, - trash=False) - kill_house_free_sale_bar_info = KillHouseFreeSaleBarInformation.objects.filter( - kill_house__in=kill_houses, - archive_wage=False, calculate_status=True, date__date__gte=date1, date__date__lte=date2, - trash=False) - - slaughter_transactions = InternalTransaction.objects.filter( - kill_house__in=kill_houses, status='completed', date__date__gte=date1, date__date__lte=date2, - trash=False) - poultry_transactions = InternalTransaction.objects.filter( - poultry__isnull=False, status='completed', date__date__gte=date1, date__date__lte=date2, - trash=False) - - poultry_requests = PoultryRequest.objects.filter(trash=False, state_process__in=('pending', 'accepted'), - province_state__in=('pending', 'accepted'), out=True, - out_province_request_cancel=False, - temporary_trash=False, send_date__date__gte=date1, - send_date__date__lte=date2, - wage_pay=True, has_wage=True, - temporary_deleted=False) - difference_requests = BarDifferenceRequest.objects.filter(kill_house__in=kill_houses, trash=False, - create_date__date__gte=date1, - create_date__date__lte=date2, - state='accepted') - else: - province_kill_requests = ProvinceKillRequest.objects.filter(killhouse_user__in=kill_houses, trash=False, - archive_wage=False, - return_to_province=False, - state__in=('pending', 'accepted'), - first_car_allocated_quantity=0).order_by( - 'id') - return_province_kill_requests = ProvinceKillRequest.objects.filter(killhouse_user__in=kill_houses, - trash=True, return_trash=True, - archive_wage=False, - return_to_province=False, - state__in=('pending', 'accepted'), - first_car_allocated_quantity=0).order_by( - 'id') - kill_house_requests = KillHouseRequest.objects.filter( - Q(Q(killhouse_user__in=kill_houses) & Q(killer__in=kill_houses)) | Q( - Q(killhouse_user__in=kill_houses) & Q(killer__isnull=True)) | Q( - Q(killhouse_user__in=kill_houses) | Q(killer__in=kill_houses)), archive_wage=False, - trash=False, calculate_status=True - ) - return_kill_house_requests = KillHouseRequest.objects.filter( - Q(Q(killhouse_user__in=kill_houses) & Q(killer__in=kill_houses)) | Q( - Q(killhouse_user__in=kill_houses) & Q(killer__isnull=True)) | Q( - Q(killhouse_user__in=kill_houses) | Q(killer__in=kill_houses)), archive_wage=False, - trash=True, return_trash=True, calculate_status=True - ) - kill_house_free_bar_info = KillHouseFreeBarInformation.objects.filter(kill_house__in=kill_houses, - archive_wage=False, - calculate_status=True, - trash=False) - kill_house_free_sale_bar_info = KillHouseFreeSaleBarInformation.objects.filter( - kill_house__in=kill_houses, - archive_wage=False, calculate_status=True, - trash=False) - - slaughter_transactions = InternalTransaction.objects.filter( - kill_house__in=kill_houses, status='completed', - trash=False) - poultry_transactions = InternalTransaction.objects.filter( - poultry__isnull=False, status='completed', - trash=False) - - poultry_requests = PoultryRequest.objects.filter(trash=False, state_process__in=('pending', 'accepted'), - province_state__in=('pending', 'accepted'), out=True, - out_province_request_cancel=False, - temporary_trash=False, - wage_pay=True, has_wage=True, - temporary_deleted=False) - difference_requests = BarDifferenceRequest.objects.filter(kill_house__in=kill_houses, trash=False, - state='accepted') - - out_province_poultry_request_weight = \ - poultry_requests.aggregate(total=Sum(F('quantity') * F('Index_weight')))[ - 'total'] or 0 - out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('total_wage_amount'))[ - 'total'] or 0 - union_out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('union_share'))[ - 'total'] or 0 - company_out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('company_share'))[ - 'total'] or 0 - guilds_out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('guilds_share'))[ - 'total'] or 0 - other_out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('other_share'))[ - 'total'] or 0 - - off = kill_houses.aggregate(total=Sum('off'))[ - 'total'] or 0 - - total_paid_wage = slaughter_transactions.aggregate(total=Sum('amount'))[ - 'total'] or 0 - total_paid_wage += poultry_transactions.aggregate(total=Sum('amount'))[ - 'total'] or 0 - - total_province_live_weight = province_kill_requests.aggregate(total=Sum('total_killed_weight'))[ - 'total'] or 0 - total_province_live_weight += kill_house_requests.aggregate(total=Sum('accepted_real_weight'))['total'] or 0 - # total_out_selling_province_carcasses_weight = \ - # kill_house_free_sale_bar_info.aggregate(total=Sum('real_weight_of_carcasses'))['total'] or 0 - # total_out_selling_province_quarantine_carcasses_weight = \ - # kill_house_free_sale_bar_info.aggregate(total=Sum('quarantine_weight_of_carcasses'))['total'] or 0 - - # sum_quarantine_carcasses_weight = \ - # kill_house_free_sale_bar_info.filter(quarantine_weight_of_carcasses__gt=0).aggregate( - # total_weight=Sum( - # Case( - # When(real_weight_of_carcasses__lt=F('quarantine_weight_of_carcasses'), - # then=F('real_weight_of_carcasses')), - # default=F('quarantine_weight_of_carcasses'), - # output_field=FloatField() - # ) - # ) - # ) - # total_out_selling_province_quarantine_carcasses_weight = sum_quarantine_carcasses_weight[ - # 'total_weight'] or 0 - - total_province_live_weight += \ - difference_requests.aggregate(total=Sum('weight'))['total'] or 0 - difference_requests_weight = \ - difference_requests.aggregate(total=Sum('weight'))['total'] or 0 - return_total_province_live_weight = \ - return_province_kill_requests.aggregate(total=Sum('total_killed_weight'))[ - 'total'] or 0 - return_total_province_live_weight += \ - return_kill_house_requests.aggregate(total=Sum('accepted_real_weight'))['total'] or 0 - final_date = '2025-05-28' - total_out_selling_province_carcasses_weight = \ - kill_house_free_sale_bar_info.filter(date__date__lte=final_date).aggregate( - total=Sum('real_weight_of_carcasses'))['total'] or 0 - new_total_out_selling_province_carcasses_weight = \ - kill_house_free_sale_bar_info.filter(date__date__gt=final_date, - quarantine_weight_of_carcasses__gt=0).aggregate( - total_weight=Sum( - Case( - When(real_weight_of_carcasses__lt=F('quarantine_weight_of_carcasses'), - then=F('real_weight_of_carcasses')), - default=F('quarantine_weight_of_carcasses'), - output_field=FloatField() - ) - ) - ) - new_out_selling = new_total_out_selling_province_carcasses_weight['total_weight'] or 0 - - total_out_selling_province_carcasses_weight += new_out_selling - - if wage_counting_type == 'live': - total_province_carcasses_weight = total_province_live_weight - - total_pure_province_carcasses_weight = total_province_carcasses_weight - else: - return_total_province_live_weight = int(return_total_province_live_weight * 0.75) - total_province_carcasses_weight = total_province_live_weight * 0.75 - difference_requests_weight = difference_requests_weight * 0.75 - - total_out_carcasses_buying_for_pure_province_carcasses_weight = \ - kill_house_free_bar_info.aggregate(total=Sum('weight_of_carcasses'))['total'] or 0 - if date1: - total_pure_province_carcasses_weight = total_province_carcasses_weight - get_difference_carcasses_weight( - kill_houses, date1, date2) - else: - total_pure_province_carcasses_weight = total_province_carcasses_weight - get_difference_carcasses_weight( - kill_houses) - total_out_live_buying_province_carcasses_weight = \ - kill_house_free_bar_info.filter(buy_type='live').aggregate(total=Sum('live_weight'))['total'] or 0 - real_total_out_live_buying_province_carcasses_weight = total_out_live_buying_province_carcasses_weight - if new_out_selling_count_wage: - if out_selling_ignore: - before_total_out_live_buying_province_carcasses_weight = \ - kill_house_free_bar_info.filter(create_date__date__lt=new_out_selling_count_wage_date, - buy_type='live').aggregate(total=Sum('live_weight'))[ - 'total'] or 0 - after_total_out_live_buying_province_carcasses_weight = \ - kill_house_free_bar_info.filter(create_date__date__gte=new_out_selling_count_wage_date, - buy_type='live').aggregate(total=Sum('live_weight'))[ - 'total'] or 0 - get_new_wage = get_new_wage_for_free_buying(kill_house_free_sale_bar_info) - - before_new_out_selling = get_new_wage['before_new_out_selling'] - after_new_out_selling = get_new_wage['after_new_out_selling'] - max_amount = before_total_out_live_buying_province_carcasses_weight * 0.80 - if max_amount <= before_new_out_selling: - before_total_out_live_buying_province_carcasses_weight -= max_amount - else: - before_total_out_live_buying_province_carcasses_weight -= before_new_out_selling - - if after_total_out_live_buying_province_carcasses_weight > after_new_out_selling: - extra_company_amount = int(after_new_out_selling * extra_company_amount) - after_total_out_live_buying_province_carcasses_weight -= after_new_out_selling - - else: - extra_company_amount = int( - after_total_out_live_buying_province_carcasses_weight * extra_company_amount) - - after_total_out_live_buying_province_carcasses_weight = 0 - - total_out_live_buying_province_carcasses_weight = before_total_out_live_buying_province_carcasses_weight + after_total_out_live_buying_province_carcasses_weight - company_before_total_out_live_buying_province_carcasses_weight = before_total_out_live_buying_province_carcasses_weight - - else: - if out_selling_ignore: - max_amount = total_out_live_buying_province_carcasses_weight * 0.80 - if max_amount <= new_out_selling: - total_out_live_buying_province_carcasses_weight -= max_amount - else: - total_out_live_buying_province_carcasses_weight -= new_out_selling - - total_out_live_buying_province_carcasses_weight = get_kill_houses_out_buying_info(kill_houses) - - total_out_carcasses_buying_province_carcasses_weight = \ - kill_house_free_bar_info.filter(buy_type='carcass').aggregate(total=Sum('weight_of_carcasses'))[ - 'total'] or 0 - total_pure_province_carcasses_price = total_pure_province_carcasses_weight * province_live_wage_amount - difference_requests_price = difference_requests_weight * province_live_wage_amount - total_return_pure_province_carcasses_price = return_total_province_live_weight * province_live_wage_amount - total_out_selling_province_carcasses_price = total_out_selling_province_carcasses_weight * free_sell_carcesses_weight_amount - - if new_out_selling_count_wage: - total_out_live_buying_province_carcasses_price = int( - (before_total_out_live_buying_province_carcasses_weight * before_out_buying_count_wage_amount) + ( - after_total_out_live_buying_province_carcasses_weight * free_buying_live_weight_amount)) - - before_total_out_live_buying_province_carcasses_price = before_total_out_live_buying_province_carcasses_weight * before_out_buying_count_wage_amount - else: - total_out_live_buying_province_carcasses_price = total_out_live_buying_province_carcasses_weight * free_buying_live_weight_amount - - # total_out_live_buying_province_carcasses_price = total_out_live_buying_province_carcasses_weight * free_buying_live_weight_amount - total_out_carcasses_buying_province_carcasses_price = total_out_carcasses_buying_province_carcasses_weight * free_buying_carcesses_weight_amount - total_price = total_pure_province_carcasses_price + total_out_selling_province_carcasses_price + total_out_live_buying_province_carcasses_price + total_out_carcasses_buying_province_carcasses_price + out_province_poultry_request_wage + extra_company_amount + total_return_pure_province_carcasses_price - - percentages_wage_type = PercentageOfWageType.objects.filter(trash=False) - union_province_kill_request_percent = percentages_wage_type.filter( - wage_type__en_name='province-kill-request', share_type__en_name='union').first().percent / 100 - company_province_kill_request_percent = percentages_wage_type.filter( - wage_type__en_name='province-kill-request', share_type__en_name='company').first().percent / 100 - guilds_province_kill_request_percent = percentages_wage_type.filter( - wage_type__en_name='province-kill-request', share_type__en_name='guilds').first().percent / 100 - other_province_kill_request_percent = percentages_wage_type.filter( - wage_type__en_name='province-kill-request', share_type__en_name='other').first().percent / 100 - - union_free_buying_live_percent = percentages_wage_type.filter(wage_type__en_name='live-buy', - share_type__en_name='union').first().percent / 100 - union_free_buying_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-buy', - share_type__en_name='union').first().percent / 100 - company_free_buying_live_percent = percentages_wage_type.filter(wage_type__en_name='live-buy', - share_type__en_name='company').first().percent / 100 - company_free_buying_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-buy', - share_type__en_name='company').first().percent / 100 - guilds_free_buying_live_percent = percentages_wage_type.filter(wage_type__en_name='live-buy', - share_type__en_name='guilds').first().percent / 100 - guilds_free_buying_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-buy', - share_type__en_name='guilds').first().percent / 100 - other_free_buying_live_percent = percentages_wage_type.filter(wage_type__en_name='live-buy', - share_type__en_name='other').first().percent / 100 - other_free_buying_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-buy', - share_type__en_name='other').first().percent / 100 - - union_free_sell_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-sell', - share_type__en_name='union').first().percent / 100 - company_free_sell_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-sell', - share_type__en_name='company').first().percent / 100 - guilds_free_sell_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-sell', - share_type__en_name='guilds').first().percent / 100 - other_free_sell_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-sell', - share_type__en_name='other').first().percent / 100 - - union_province_kill_request_wage = total_pure_province_carcasses_price * union_province_kill_request_percent - return_union_province_kill_request_wage = total_return_pure_province_carcasses_price * union_province_kill_request_percent - union_free_buying_live_wage = ( - total_out_live_buying_province_carcasses_price - before_total_out_live_buying_province_carcasses_price) * union_free_buying_live_percent - union_free_buying_carcasses_wage = total_out_carcasses_buying_province_carcasses_price * union_free_buying_carcasses_percent - union_free_sell_carcasses_wage = total_out_selling_province_carcasses_price * union_free_sell_carcasses_percent - union_total_wage = union_province_kill_request_wage + union_free_buying_live_wage + union_free_buying_carcasses_wage + union_free_sell_carcasses_wage + union_out_province_poultry_request_wage + return_union_province_kill_request_wage - union_total_paid_wage = slaughter_transactions.aggregate(total=Sum('union_share'))['total'] or 0 - union_total_paid_wage += poultry_transactions.aggregate(total=Sum('union_share'))['total'] or 0 - union_total_unpaid_wage = union_total_wage - union_total_paid_wage - - shares_list.append({ - "name": "اتحادیه", - "out_province_poultry_request_wage": union_out_province_poultry_request_wage, - "province_kill_request_wage": union_province_kill_request_wage, - "return_province_kill_request_wage": return_union_province_kill_request_wage, - "free_buying_live_wage": union_free_buying_live_wage, - "free_buying_carcasses_wage": union_free_buying_carcasses_wage, - "free_sell_carcasses_wage": union_free_sell_carcasses_wage, - "total_wage": union_total_wage, - "total_paid_wage": union_total_paid_wage, - "total_unpaid_wage": union_total_unpaid_wage, - - }) - - guilds_difference_requests_price = difference_requests_price * guilds_province_kill_request_percent - other_difference_requests_price = difference_requests_price * other_province_kill_request_percent - guild_return_province_kill_request_wage = total_return_pure_province_carcasses_price * guilds_province_kill_request_percent - other_return_province_kill_request_wage = total_return_pure_province_carcasses_price * other_province_kill_request_percent - - company_province_kill_request_wage = ( - total_pure_province_carcasses_price * company_province_kill_request_percent) + ( - guilds_difference_requests_price + other_difference_requests_price) - return_company_province_kill_request_wage = ( - total_return_pure_province_carcasses_price * company_province_kill_request_percent) + ( - guild_return_province_kill_request_wage + other_return_province_kill_request_wage) - company_free_buying_live_wage = (( - total_out_live_buying_province_carcasses_price - before_total_out_live_buying_province_carcasses_price) * company_free_buying_live_percent) + before_total_out_live_buying_province_carcasses_price - company_free_buying_carcasses_wage = total_out_carcasses_buying_province_carcasses_price * company_free_buying_carcasses_percent - company_free_sell_carcasses_wage = total_out_selling_province_carcasses_price * company_free_sell_carcasses_percent - company_total_wage = company_province_kill_request_wage + company_free_buying_live_wage + company_free_buying_carcasses_wage + company_free_sell_carcasses_wage + company_out_province_poultry_request_wage + return_company_province_kill_request_wage - company_total_paid_wage = slaughter_transactions.aggregate(total=Sum('company_share'))['total'] or 0 - company_total_paid_wage += poultry_transactions.aggregate(total=Sum('company_share'))['total'] or 0 - # company_total_pure_paid_wage = company_total_paid_wage - (company_total_paid_wage * 0.08)) - company_total_unpaid_wage = company_total_wage - company_total_paid_wage - - shares_list.append({ - "name": "شرکت", - "out_province_poultry_request_wage": company_out_province_poultry_request_wage, - "province_kill_request_wage": company_province_kill_request_wage, - "return_province_kill_request_wage": return_company_province_kill_request_wage, - "free_buying_live_wage": company_free_buying_live_wage, - "free_buying_carcasses_wage": company_free_buying_carcasses_wage, - "free_sell_carcasses_wage": company_free_sell_carcasses_wage, - "total_wage": company_total_wage, - "total_paid_wage": company_total_paid_wage, - "total_unpaid_wage": company_total_unpaid_wage, - - }) - - guilds_province_kill_request_wage = ( - total_pure_province_carcasses_price * guilds_province_kill_request_percent) - guilds_difference_requests_price - # return_guilds_province_kill_request_wage = total_return_pure_province_carcasses_price * guilds_province_kill_request_percent - guilds_free_buying_live_wage = ( - total_out_live_buying_province_carcasses_price - before_total_out_live_buying_province_carcasses_price) * guilds_free_buying_live_percent - guilds_free_buying_carcasses_wage = total_out_carcasses_buying_province_carcasses_price * guilds_free_buying_carcasses_percent - guilds_free_sell_carcasses_wage = total_out_selling_province_carcasses_price * guilds_free_sell_carcasses_percent - guilds_total_wage = guilds_province_kill_request_wage + guilds_free_buying_live_wage + guilds_free_buying_carcasses_wage + guilds_free_sell_carcasses_wage + guilds_out_province_poultry_request_wage - guilds_total_paid_wage = slaughter_transactions.aggregate(total=Sum('guilds_share'))['total'] or 0 - guilds_total_paid_wage += poultry_transactions.aggregate(total=Sum('guilds_share'))['total'] or 0 - guilds_total_unpaid_wage = guilds_total_wage - guilds_total_paid_wage - - shares_list.append({ - "name": "صنف پروتئین", - "out_province_poultry_request_wage": guilds_out_province_poultry_request_wage, - "province_kill_request_wage": guilds_province_kill_request_wage, - "return_province_kill_request_wage": 0, - "free_buying_live_wage": guilds_free_buying_live_wage, - "free_buying_carcasses_wage": guilds_free_buying_carcasses_wage, - "free_sell_carcasses_wage": guilds_free_sell_carcasses_wage, - "total_wage": guilds_total_wage, - "total_paid_wage": guilds_total_paid_wage, - "total_unpaid_wage": guilds_total_unpaid_wage, - - }) - - other_province_kill_request_wage = ( - total_pure_province_carcasses_price * other_province_kill_request_percent) - other_difference_requests_price - # return_other_province_kill_request_wage = total_return_pure_province_carcasses_price * other_province_kill_request_percent - other_free_buying_live_wage = ( - total_out_live_buying_province_carcasses_price - before_total_out_live_buying_province_carcasses_price) * other_free_buying_live_percent - other_free_buying_carcasses_wage = total_out_carcasses_buying_province_carcasses_price * other_free_buying_carcasses_percent - other_free_sell_carcasses_wage = total_out_selling_province_carcasses_price * other_free_sell_carcasses_percent - other_total_wage = other_province_kill_request_wage + other_free_buying_live_wage + other_free_buying_carcasses_wage + other_free_sell_carcasses_wage + other_out_province_poultry_request_wage - other_total_paid_wage = slaughter_transactions.aggregate(total=Sum('other_share'))['total'] or 0 - other_total_paid_wage += poultry_transactions.aggregate(total=Sum('other_share'))['total'] or 0 - other_total_unpaid_wage = other_total_wage - other_total_paid_wage - - shares_list.append({ - "name": "دامپزشک", - "out_province_poultry_request_wage": other_out_province_poultry_request_wage, - "province_kill_request_wage": other_province_kill_request_wage, - "return_province_kill_request_wage": 0, - "free_buying_live_wage": other_free_buying_live_wage, - "free_buying_carcasses_wage": other_free_buying_carcasses_wage, - "free_sell_carcasses_wage": other_free_sell_carcasses_wage, - "total_wage": other_total_wage, - "total_paid_wage": other_total_paid_wage, - "total_unpaid_wage": other_total_unpaid_wage, - - }) - - return { - "wage_counting_type": wage_counting_type, - "total_wage": total_price, - "total_paid_wage": total_paid_wage, - "off": off, - "total_unpaid_wage": total_price - (total_paid_wage + off), - "out_province_poultry_request_weight": out_province_poultry_request_weight, - "out_province_poultry_request_wage": out_province_poultry_request_wage, - "province_kill_requests_total_wage": total_pure_province_carcasses_price, - "province_kill_requests_total_weight": total_pure_province_carcasses_weight, - "free_bars_live_total_wage": total_out_live_buying_province_carcasses_price, - "free_bars_live_total_weight": real_total_out_live_buying_province_carcasses_weight, - "free_bars_carcases_total_wage": total_out_carcasses_buying_province_carcasses_price, - "free_bars_carcases_total_weight": total_out_carcasses_buying_province_carcasses_weight, - "free_bars_out_province_carcases_total_wage": total_out_selling_province_carcasses_price, - "free_bars_out_province_carcases_total_weight": total_out_selling_province_carcasses_weight, - "total_province_live_weight": total_province_live_weight, - "total_province_carcasses_weight": total_province_carcasses_weight, - "province_live_wage_amount": province_live_wage_amount, - "free_buying_live_weight_amount": free_buying_live_weight_amount, - "free_buying_carcesses_weight_amount": free_buying_carcesses_weight_amount, - "free_sell_carcesses_weight_amount": free_sell_carcesses_weight_amount, - "out_province_poultry_request_wage_amount": out_province_poultry_request_wage_amount, - "extra_company_amount": extra_company_amount, - "shares": shares_list, - "return_total_province_live_weight": return_total_province_live_weight, - "total_return_pure_province_carcasses_price": total_return_pure_province_carcasses_price, - } # class TotalWageInformationSerializer(serializers.ModelSerializer): # wage_info = serializers.SerializerMethodField('get_wage_info') # @@ -4793,77 +4104,277 @@ class TotalWageInformationSerializer(serializers.ModelSerializer): # # # else: -# total_wage = 0 -# total_paid_wage = 0 -# off = 0 -# total_unpaid_wage = 0 -# province_kill_requests_total_wage =0 -# province_kill_requests_total_weight = 0 -# free_bars_live_total_wage = 0 -# free_bars_live_total_weight = 0 -# free_bars_carcases_total_wage = 0 -# free_bars_carcases_total_weight = 0 -# free_bars_out_province_carcases_total_wage = 0 -# free_bars_out_province_carcases_total_weight = 0 -# total_province_live_weight =0 -# total_province_carcasses_weight =0 -# province_live_wage_amount = 0 -# free_buying_live_weight_amount = 0 -# free_buying_carcesses_weight_amount = 0 -# free_sell_carcesses_weight_amount = 0 -# return_total_province_live_weight = 0 -# total_return_pure_province_carcasses_price = 0 -# total_pure_province_carcasses_price = 0 -# return_total_pure_province_carcasses_price = 0 -# total_out_selling_province_carcasses_price = 0 -# difference_requests_price =0 +# kill_houses = KillHouse.objects.filter(out_province=False, trash=False).order_by('id') +# if date1: # -# before_total_out_live_buying_province_carcasses_price = 0 -# total_out_live_buying_province_carcasses_price = 0 -# total_out_carcasses_buying_province_carcasses_price = 0 +# province_kill_requests = ProvinceKillRequest.objects.filter(killhouse_user__in=kill_houses, trash=False, +# archive_wage=False, +# return_to_province=False, +# state__in=('pending', 'accepted'), +# kill_request__recive_date__date__gte=date1, +# kill_request__recive_date__date__lte=date2, +# first_car_allocated_quantity=0).order_by( +# 'id') +# return_province_kill_requests = ProvinceKillRequest.objects.filter(killhouse_user__in=kill_houses, +# trash=True, return_trash=True, +# archive_wage=False, +# return_to_province=False, +# state__in=('pending', 'accepted'), +# kill_request__recive_date__date__gte=date1, +# kill_request__recive_date__date__lte=date2, +# first_car_allocated_quantity=0).order_by( +# 'id') +# kill_house_requests = KillHouseRequest.objects.filter( +# Q(Q(killhouse_user__in=kill_houses) & Q(killer__in=kill_houses)) | Q( +# Q(killhouse_user__in=kill_houses) & Q(killer__isnull=True)) | Q( +# Q(killhouse_user__in=kill_houses) | Q(killer__in=kill_houses)), archive_wage=False, +# kill_request__recive_date__date__gte=date1, kill_request__recive_date__date__lte=date2, +# trash=False, calculate_status=True +# ) +# return_kill_house_requests = KillHouseRequest.objects.filter( +# Q(Q(killhouse_user__in=kill_houses) & Q(killer__in=kill_houses)) | Q( +# Q(killhouse_user__in=kill_houses) & Q(killer__isnull=True)) | Q( +# Q(killhouse_user__in=kill_houses) | Q(killer__in=kill_houses)), archive_wage=False, +# kill_request__recive_date__date__gte=date1, kill_request__recive_date__date__lte=date2, +# trash=True, return_trash=True, calculate_status=True +# ) +# kill_house_free_bar_info = KillHouseFreeBarInformation.objects.filter(kill_house__in=kill_houses, +# archive_wage=False, +# calculate_status=True, +# create_date__date__gte=date1, +# create_date__date__lte=date2, +# trash=False) +# kill_house_free_sale_bar_info = KillHouseFreeSaleBarInformation.objects.filter( +# kill_house__in=kill_houses, +# archive_wage=False, calculate_status=True, date__date__gte=date1, date__date__lte=date2, +# trash=False) # -# guilds_difference_requests_price = 0 -# other_difference_requests_price = 0 -# guild_return_province_kill_request_wage = 0 -# other_return_province_kill_request_wage = 0 +# slaughter_transactions = InternalTransaction.objects.filter( +# kill_house__in=kill_houses, status='completed', date__date__gte=date1, date__date__lte=date2, +# trash=False) +# poultry_transactions = InternalTransaction.objects.filter( +# poultry__isnull=False, status='completed', date__date__gte=date1, date__date__lte=date2, +# trash=False) # -# union_province_kill_request_wage = 0 -# return_union_province_kill_request_wage = 0 -# union_free_buying_live_wage =0 -# union_free_buying_carcasses_wage = 0 -# union_free_sell_carcasses_wage = 0 -# union_total_wage = 0 -# union_total_paid_wage = 0 -# union_total_unpaid_wage = 0 -# company_province_kill_request_wage =0 -# return_company_province_kill_request_wage = 0 -# company_free_buying_live_wage = 0 -# company_free_buying_carcasses_wage = 0 -# company_free_sell_carcasses_wage = 0 -# company_total_wage =0 -# company_total_paid_wage = 0 -# company_total_unpaid_wage = 0 +# poultry_requests = PoultryRequest.objects.filter(trash=False, state_process__in=('pending', 'accepted'), +# province_state__in=('pending', 'accepted'), out=True, +# out_province_request_cancel=False, +# temporary_trash=False, send_date__date__gte=date1, +# send_date__date__lte=date2, +# wage_pay=True, has_wage=True, +# temporary_deleted=False) +# difference_requests = BarDifferenceRequest.objects.filter(kill_house__in=kill_houses, trash=False, +# create_date__date__gte=date1, +# create_date__date__lte=date2, +# state='accepted') +# else: +# province_kill_requests = ProvinceKillRequest.objects.filter(killhouse_user__in=kill_houses, trash=False, +# archive_wage=False, +# return_to_province=False, +# state__in=('pending', 'accepted'), +# first_car_allocated_quantity=0).order_by( +# 'id') +# return_province_kill_requests = ProvinceKillRequest.objects.filter(killhouse_user__in=kill_houses, +# trash=True, return_trash=True, +# archive_wage=False, +# return_to_province=False, +# state__in=('pending', 'accepted'), +# first_car_allocated_quantity=0).order_by( +# 'id') +# kill_house_requests = KillHouseRequest.objects.filter( +# Q(Q(killhouse_user__in=kill_houses) & Q(killer__in=kill_houses)) | Q( +# Q(killhouse_user__in=kill_houses) & Q(killer__isnull=True)) | Q( +# Q(killhouse_user__in=kill_houses) | Q(killer__in=kill_houses)), archive_wage=False, +# trash=False, calculate_status=True +# ) +# return_kill_house_requests = KillHouseRequest.objects.filter( +# Q(Q(killhouse_user__in=kill_houses) & Q(killer__in=kill_houses)) | Q( +# Q(killhouse_user__in=kill_houses) & Q(killer__isnull=True)) | Q( +# Q(killhouse_user__in=kill_houses) | Q(killer__in=kill_houses)), archive_wage=False, +# trash=True, return_trash=True, calculate_status=True +# ) +# kill_house_free_bar_info = KillHouseFreeBarInformation.objects.filter(kill_house__in=kill_houses, +# archive_wage=False, +# calculate_status=True, +# trash=False) +# kill_house_free_sale_bar_info = KillHouseFreeSaleBarInformation.objects.filter( +# kill_house__in=kill_houses, +# archive_wage=False, calculate_status=True, +# trash=False) # -# guilds_province_kill_request_wage = 0 -# return_guilds_province_kill_request_wage = 0 -# guilds_free_buying_live_wage = 0 -# guilds_free_buying_carcasses_wage = 0 -# guilds_free_sell_carcasses_wage = 0 -# guilds_total_wage = 0 -# guilds_total_paid_wage = 0 -# guilds_total_unpaid_wage = 0 +# slaughter_transactions = InternalTransaction.objects.filter( +# kill_house__in=kill_houses, status='completed', +# trash=False) +# poultry_transactions = InternalTransaction.objects.filter( +# poultry__isnull=False, status='completed', +# trash=False) +# +# poultry_requests = PoultryRequest.objects.filter(trash=False, state_process__in=('pending', 'accepted'), +# province_state__in=('pending', 'accepted'), out=True, +# out_province_request_cancel=False, +# temporary_trash=False, +# wage_pay=True, has_wage=True, +# temporary_deleted=False) +# difference_requests = BarDifferenceRequest.objects.filter(kill_house__in=kill_houses, trash=False, +# state='accepted') +# +# out_province_poultry_request_weight = \ +# poultry_requests.aggregate(total=Sum(F('quantity') * F('Index_weight')))[ +# 'total'] or 0 +# out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('total_wage_amount'))[ +# 'total'] or 0 +# union_out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('union_share'))[ +# 'total'] or 0 +# company_out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('company_share'))[ +# 'total'] or 0 +# guilds_out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('guilds_share'))[ +# 'total'] or 0 +# other_out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('other_share'))[ +# 'total'] or 0 +# +# off = kill_houses.aggregate(total=Sum('off'))[ +# 'total'] or 0 +# +# total_paid_wage = slaughter_transactions.aggregate(total=Sum('amount'))[ +# 'total'] or 0 +# total_paid_wage += poultry_transactions.aggregate(total=Sum('amount'))[ +# 'total'] or 0 +# +# total_province_live_weight = province_kill_requests.aggregate(total=Sum('total_killed_weight'))[ +# 'total'] or 0 +# total_province_live_weight += kill_house_requests.aggregate(total=Sum('accepted_real_weight'))['total'] or 0 +# # total_out_selling_province_carcasses_weight = \ +# # kill_house_free_sale_bar_info.aggregate(total=Sum('real_weight_of_carcasses'))['total'] or 0 +# # total_out_selling_province_quarantine_carcasses_weight = \ +# # kill_house_free_sale_bar_info.aggregate(total=Sum('quarantine_weight_of_carcasses'))['total'] or 0 +# +# # sum_quarantine_carcasses_weight = \ +# # kill_house_free_sale_bar_info.filter(quarantine_weight_of_carcasses__gt=0).aggregate( +# # total_weight=Sum( +# # Case( +# # When(real_weight_of_carcasses__lt=F('quarantine_weight_of_carcasses'), +# # then=F('real_weight_of_carcasses')), +# # default=F('quarantine_weight_of_carcasses'), +# # output_field=FloatField() +# # ) +# # ) +# # ) +# # total_out_selling_province_quarantine_carcasses_weight = sum_quarantine_carcasses_weight[ +# # 'total_weight'] or 0 +# +# total_province_live_weight += \ +# difference_requests.aggregate(total=Sum('weight'))['total'] or 0 +# difference_requests_weight = \ +# difference_requests.aggregate(total=Sum('weight'))['total'] or 0 +# return_total_province_live_weight = \ +# return_province_kill_requests.aggregate(total=Sum('total_killed_weight'))[ +# 'total'] or 0 +# return_total_province_live_weight += \ +# return_kill_house_requests.aggregate(total=Sum('accepted_real_weight'))['total'] or 0 +# final_date = '2025-05-28' +# total_out_selling_province_carcasses_weight = \ +# kill_house_free_sale_bar_info.filter(date__date__lte=final_date).aggregate( +# total=Sum('real_weight_of_carcasses'))['total'] or 0 +# new_total_out_selling_province_carcasses_weight = \ +# kill_house_free_sale_bar_info.filter(date__date__gt=final_date, +# quarantine_weight_of_carcasses__gt=0).aggregate( +# total_weight=Sum( +# Case( +# When(real_weight_of_carcasses__lt=F('quarantine_weight_of_carcasses'), +# then=F('real_weight_of_carcasses')), +# default=F('quarantine_weight_of_carcasses'), +# output_field=FloatField() +# ) +# ) +# ) +# new_out_selling = new_total_out_selling_province_carcasses_weight['total_weight'] or 0 +# +# total_out_selling_province_carcasses_weight += new_out_selling +# +# if wage_counting_type == 'live': +# total_province_carcasses_weight = total_province_live_weight +# +# total_pure_province_carcasses_weight = total_province_carcasses_weight +# else: +# return_total_province_live_weight = int(return_total_province_live_weight * 0.75) +# total_province_carcasses_weight = total_province_live_weight * 0.75 +# difference_requests_weight = difference_requests_weight * 0.75 +# +# total_out_carcasses_buying_for_pure_province_carcasses_weight = \ +# kill_house_free_bar_info.aggregate(total=Sum('weight_of_carcasses'))['total'] or 0 +# if date1: +# total_pure_province_carcasses_weight = total_province_carcasses_weight - get_difference_carcasses_weight( +# kill_houses, date1, date2) +# else: +# total_pure_province_carcasses_weight = total_province_carcasses_weight - get_difference_carcasses_weight( +# kill_houses) +# total_out_live_buying_province_carcasses_weight = \ +# kill_house_free_bar_info.filter(buy_type='live').aggregate(total=Sum('live_weight'))['total'] or 0 +# real_total_out_live_buying_province_carcasses_weight = total_out_live_buying_province_carcasses_weight +# if new_out_selling_count_wage: +# if out_selling_ignore: +# before_total_out_live_buying_province_carcasses_weight = \ +# kill_house_free_bar_info.filter(create_date__date__lt=new_out_selling_count_wage_date, +# buy_type='live').aggregate(total=Sum('live_weight'))[ +# 'total'] or 0 +# after_total_out_live_buying_province_carcasses_weight = \ +# kill_house_free_bar_info.filter(create_date__date__gte=new_out_selling_count_wage_date, +# buy_type='live').aggregate(total=Sum('live_weight'))[ +# 'total'] or 0 +# get_new_wage = get_new_wage_for_free_buying(kill_house_free_sale_bar_info) +# +# before_new_out_selling = get_new_wage['before_new_out_selling'] +# after_new_out_selling = get_new_wage['after_new_out_selling'] +# max_amount = before_total_out_live_buying_province_carcasses_weight * 0.80 +# if max_amount <= before_new_out_selling: +# before_total_out_live_buying_province_carcasses_weight -= max_amount +# else: +# before_total_out_live_buying_province_carcasses_weight -= before_new_out_selling +# +# if after_total_out_live_buying_province_carcasses_weight > after_new_out_selling: +# extra_company_amount = int(after_new_out_selling * extra_company_amount) +# after_total_out_live_buying_province_carcasses_weight -= after_new_out_selling +# +# else: +# extra_company_amount = int( +# after_total_out_live_buying_province_carcasses_weight * extra_company_amount) +# +# after_total_out_live_buying_province_carcasses_weight = 0 +# +# total_out_live_buying_province_carcasses_weight = before_total_out_live_buying_province_carcasses_weight + after_total_out_live_buying_province_carcasses_weight +# company_before_total_out_live_buying_province_carcasses_weight = before_total_out_live_buying_province_carcasses_weight +# +# else: +# if out_selling_ignore: +# max_amount = total_out_live_buying_province_carcasses_weight * 0.80 +# if max_amount <= new_out_selling: +# total_out_live_buying_province_carcasses_weight -= max_amount +# else: +# total_out_live_buying_province_carcasses_weight -= new_out_selling +# +# total_out_live_buying_province_carcasses_weight = get_kill_houses_out_buying_info(kill_houses) +# +# total_out_carcasses_buying_province_carcasses_weight = \ +# kill_house_free_bar_info.filter(buy_type='carcass').aggregate(total=Sum('weight_of_carcasses'))[ +# 'total'] or 0 +# total_pure_province_carcasses_price = total_pure_province_carcasses_weight * province_live_wage_amount +# difference_requests_price = difference_requests_weight * province_live_wage_amount +# total_return_pure_province_carcasses_price = return_total_province_live_weight * province_live_wage_amount +# total_out_selling_province_carcasses_price = total_out_selling_province_carcasses_weight * free_sell_carcesses_weight_amount +# +# if new_out_selling_count_wage: +# total_out_live_buying_province_carcasses_price = int( +# (before_total_out_live_buying_province_carcasses_weight * before_out_buying_count_wage_amount) + ( +# after_total_out_live_buying_province_carcasses_weight * free_buying_live_weight_amount)) +# +# before_total_out_live_buying_province_carcasses_price = before_total_out_live_buying_province_carcasses_weight * before_out_buying_count_wage_amount +# else: +# total_out_live_buying_province_carcasses_price = total_out_live_buying_province_carcasses_weight * free_buying_live_weight_amount +# +# # total_out_live_buying_province_carcasses_price = total_out_live_buying_province_carcasses_weight * free_buying_live_weight_amount +# total_out_carcasses_buying_province_carcasses_price = total_out_carcasses_buying_province_carcasses_weight * free_buying_carcesses_weight_amount +# total_price = total_pure_province_carcasses_price + total_out_selling_province_carcasses_price + total_out_live_buying_province_carcasses_price + total_out_carcasses_buying_province_carcasses_price + out_province_poultry_request_wage + extra_company_amount + total_return_pure_province_carcasses_price # -# other_province_kill_request_wage = 0 -# return_other_province_kill_request_wage = 0 -# other_free_buying_live_wage = 0 -# other_free_buying_carcasses_wage = 0 -# other_free_sell_carcasses_wage = 0 -# other_total_wage = 0 -# other_total_paid_wage = 0 -# other_total_unpaid_wage = 0 -# total_wage_type = WageType.objects.filter(trash=False) -# free_buying_live_weight_wage_type = total_wage_type.filter(en_name='live-buy', trash=False).first() -# free_buying_live_weight_wage_type_amount = free_buying_live_weight_wage_type.amount if free_buying_live_weight_wage_type.status == True else 0 # percentages_wage_type = PercentageOfWageType.objects.filter(trash=False) # union_province_kill_request_percent = percentages_wage_type.filter( # wage_type__en_name='province-kill-request', share_type__en_name='union').first().percent / 100 @@ -4899,168 +4410,17 @@ class TotalWageInformationSerializer(serializers.ModelSerializer): # share_type__en_name='guilds').first().percent / 100 # other_free_sell_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-sell', # share_type__en_name='other').first().percent / 100 -# if date1: -# poultry_transactions = InternalTransaction.objects.filter( -# poultry__isnull=False, status='completed', date__date__gte=date1, date__date__lte=date2, -# trash=False) -# -# poultry_requests = PoultryRequest.objects.filter(trash=False, state_process__in=('pending', 'accepted'), -# province_state__in=('pending', 'accepted'), out=True, -# out_province_request_cancel=False, -# temporary_trash=False, send_date__date__gte=date1, -# send_date__date__lte=date2, -# wage_pay=True, has_wage=True, -# temporary_deleted=False) -# -# else: -# poultry_transactions = InternalTransaction.objects.filter( -# poultry__isnull=False, status='completed', -# trash=False) -# -# poultry_requests = PoultryRequest.objects.filter(trash=False, state_process__in=('pending', 'accepted'), -# province_state__in=('pending', 'accepted'), out=True, -# out_province_request_cancel=False, -# temporary_trash=False, -# wage_pay=True, has_wage=True, -# temporary_deleted=False) -# -# -# out_province_poultry_request_weight = \ -# poultry_requests.aggregate(total=Sum(F('quantity') * F('Index_weight')))[ -# 'total'] or 0 -# out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('total_wage_amount'))[ -# 'total'] or 0 -# union_out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('union_share'))[ -# 'total'] or 0 -# company_out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('company_share'))[ -# 'total'] or 0 -# guilds_out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('guilds_share'))[ -# 'total'] or 0 -# other_out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('other_share'))[ -# 'total'] or 0 -# total_paid_wage = poultry_transactions.aggregate(total=Sum('amount'))[ -# 'total'] or 0 -# -# total_wage +=out_province_poultry_request_wage -# kill_houses = KillHouse.objects.filter(out_province=False, trash=False).order_by('id') -# for kill_house in kill_houses: -# finance_info =get_finance_info(kill_house) -# if kill_house.killer and kill_house.type == 'public': -# -# slaughter_transactions = InternalTransaction.objects.filter( -# kill_house=kill_house, parent_kill_house=kill_house, status='completed', -# trash=False) -# else: -# slaughter_transactions = InternalTransaction.objects.filter( -# Q(kill_house=kill_house) | Q(parent_kill_house=kill_house), status='completed', -# trash=False) -# -# -# -# -# total_wage += finance_info['total_price'] -# total_paid_wage += slaughter_transactions.aggregate(total=Sum('amount'))[ -# 'total'] or 0 -# off += kill_house.off -# total_unpaid_wage += finance_info['total_price'] - (total_paid_wage + kill_house.off) -# province_kill_requests_total_wage += finance_info['total_pure_province_carcasses_price'] -# province_kill_requests_total_weight += finance_info['total_pure_province_carcasses_weight'] -# free_bars_live_total_wage += finance_info['total_out_live_buying_province_carcasses_price'] -# free_bars_live_total_weight += finance_info['total_out_live_buying_province_carcasses_weight'] -# free_bars_carcases_total_wage += finance_info[ -# 'total_out_carcasses_buying_province_carcasses_price'] -# free_bars_carcases_total_weight += finance_info[ -# 'total_out_carcasses_buying_province_carcasses_weight'] -# free_bars_out_province_carcases_total_wage += finance_info[ -# 'total_out_selling_province_carcasses_price'] -# free_bars_out_province_carcases_total_weight += finance_info[ -# 'total_out_selling_province_carcasses_weight'] -# total_province_live_weight += finance_info['total_province_live_weight'] -# total_province_carcasses_weight += finance_info['total_province_carcasses_weight'] -# province_live_wage_amount += finance_info['province_live_wage_amount'] -# free_buying_live_weight_amount += finance_info['free_buying_live_weight_amount'] -# free_buying_carcesses_weight_amount += finance_info['free_buying_carcesses_weight_amount'] -# free_sell_carcesses_weight_amount += finance_info['free_sell_carcesses_weight_amount'] -# return_total_province_live_weight += finance_info['return_total_province_live_weight'] -# total_return_pure_province_carcasses_price += finance_info[ -# 'total_return_pure_province_carcasses_price'] -# -# total_pure_province_carcasses_price += finance_info['total_pure_province_carcasses_price'] -# return_total_pure_province_carcasses_price += finance_info['total_return_pure_province_carcasses_price'] -# total_out_selling_province_carcasses_price += finance_info['total_out_selling_province_carcasses_price'] -# difference_requests_price += finance_info['difference_requests_price'] -# -# if new_out_selling_count_wage: -# total_out_live_buying_province_carcasses_price += int( -# (finance_info[ -# 'before_total_out_live_buying_province_carcasses_weight'] * before_out_buying_count_wage_amount) + ( -# finance_info[ -# 'after_total_out_live_buying_province_carcasses_weight'] * free_buying_live_weight_wage_type_amount)) -# -# before_total_out_live_buying_province_carcasses_price += finance_info[ -# 'before_total_out_live_buying_province_carcasses_weight'] * before_out_buying_count_wage_amount -# else: -# total_out_live_buying_province_carcasses_price += finance_info[ -# 'total_out_live_buying_province_carcasses_price'] -# total_out_carcasses_buying_province_carcasses_price += finance_info[ -# 'total_out_carcasses_buying_province_carcasses_price'] -# -# guilds_difference_requests_price += difference_requests_price * guilds_province_kill_request_percent -# other_difference_requests_price += difference_requests_price * other_province_kill_request_percent -# guild_return_province_kill_request_wage += return_total_pure_province_carcasses_price * guilds_province_kill_request_percent -# other_return_province_kill_request_wage += return_total_pure_province_carcasses_price * other_province_kill_request_percent -# -# union_province_kill_request_wage += total_pure_province_carcasses_price * union_province_kill_request_percent -# return_union_province_kill_request_wage += return_total_pure_province_carcasses_price * union_province_kill_request_percent -# union_free_buying_live_wage += ( -# total_out_live_buying_province_carcasses_price - before_total_out_live_buying_province_carcasses_price) * union_free_buying_live_percent -# union_free_buying_carcasses_wage += total_out_carcasses_buying_province_carcasses_price * union_free_buying_carcasses_percent -# union_free_sell_carcasses_wage += total_out_selling_province_carcasses_price * union_free_sell_carcasses_percent -# union_total_wage += union_province_kill_request_wage + union_free_buying_live_wage + union_free_buying_carcasses_wage + union_free_sell_carcasses_wage + return_union_province_kill_request_wage -# union_total_paid_wage += slaughter_transactions.aggregate(total=Sum('union_share'))['total'] or 0 -# union_total_unpaid_wage += union_total_wage - union_total_paid_wage -# company_province_kill_request_wage += ( -# total_pure_province_carcasses_price * company_province_kill_request_percent) + ( -# guilds_difference_requests_price + other_difference_requests_price) -# return_company_province_kill_request_wage += ( -# return_total_pure_province_carcasses_price * company_province_kill_request_percent) + ( -# guild_return_province_kill_request_wage + other_return_province_kill_request_wage) -# company_free_buying_live_wage += (( -# total_out_live_buying_province_carcasses_price - before_total_out_live_buying_province_carcasses_price) * company_free_buying_live_percent) + before_total_out_live_buying_province_carcasses_price -# company_free_buying_carcasses_wage += total_out_carcasses_buying_province_carcasses_price * company_free_buying_carcasses_percent -# company_free_sell_carcasses_wage += total_out_selling_province_carcasses_price * company_free_sell_carcasses_percent -# company_total_wage += company_province_kill_request_wage + company_free_buying_live_wage + company_free_buying_carcasses_wage + company_free_sell_carcasses_wage + return_company_province_kill_request_wage -# company_total_paid_wage += slaughter_transactions.aggregate(total=Sum('company_share'))['total'] or 0 -# company_total_unpaid_wage += company_total_wage - company_total_paid_wage -# -# guilds_province_kill_request_wage += ( -# total_pure_province_carcasses_price * guilds_province_kill_request_percent) - guilds_difference_requests_price -# return_guilds_province_kill_request_wage += 0 -# guilds_free_buying_live_wage += ( -# total_out_live_buying_province_carcasses_price - before_total_out_live_buying_province_carcasses_price) * guilds_free_buying_live_percent -# guilds_free_buying_carcasses_wage += total_out_carcasses_buying_province_carcasses_price * guilds_free_buying_carcasses_percent -# guilds_free_sell_carcasses_wage += total_out_selling_province_carcasses_price * guilds_free_sell_carcasses_percent -# guilds_total_wage += guilds_province_kill_request_wage + guilds_free_buying_live_wage + guilds_free_buying_carcasses_wage + guilds_free_sell_carcasses_wage -# guilds_total_paid_wage += slaughter_transactions.aggregate(total=Sum('guilds_share'))['total'] or 0 -# guilds_total_unpaid_wage += guilds_total_wage - guilds_total_paid_wage -# -# other_province_kill_request_wage += ( -# total_pure_province_carcasses_price * other_province_kill_request_percent) - other_difference_requests_price -# return_other_province_kill_request_wage += 0 -# other_free_buying_live_wage += ( -# total_out_live_buying_province_carcasses_price - before_total_out_live_buying_province_carcasses_price) * other_free_buying_live_percent -# other_free_buying_carcasses_wage += total_out_carcasses_buying_province_carcasses_price * other_free_buying_carcasses_percent -# other_free_sell_carcasses_wage += total_out_selling_province_carcasses_price * other_free_sell_carcasses_percent -# other_total_wage += other_province_kill_request_wage + other_free_buying_live_wage + other_free_buying_carcasses_wage + other_free_sell_carcasses_wage -# other_total_paid_wage += slaughter_transactions.aggregate(total=Sum('other_share'))['total'] or 0 -# other_total_unpaid_wage += other_total_wage - other_total_paid_wage -# -# -# -# # +# union_province_kill_request_wage = total_pure_province_carcasses_price * union_province_kill_request_percent +# return_union_province_kill_request_wage = total_return_pure_province_carcasses_price * union_province_kill_request_percent +# union_free_buying_live_wage = ( +# total_out_live_buying_province_carcasses_price - before_total_out_live_buying_province_carcasses_price) * union_free_buying_live_percent +# union_free_buying_carcasses_wage = total_out_carcasses_buying_province_carcasses_price * union_free_buying_carcasses_percent +# union_free_sell_carcasses_wage = total_out_selling_province_carcasses_price * union_free_sell_carcasses_percent +# union_total_wage = union_province_kill_request_wage + union_free_buying_live_wage + union_free_buying_carcasses_wage + union_free_sell_carcasses_wage + union_out_province_poultry_request_wage + return_union_province_kill_request_wage +# union_total_paid_wage = slaughter_transactions.aggregate(total=Sum('union_share'))['total'] or 0 # union_total_paid_wage += poultry_transactions.aggregate(total=Sum('union_share'))['total'] or 0 -# +# union_total_unpaid_wage = union_total_wage - union_total_paid_wage # # shares_list.append({ # "name": "اتحادیه", @@ -5076,7 +4436,27 @@ class TotalWageInformationSerializer(serializers.ModelSerializer): # # }) # +# guilds_difference_requests_price = difference_requests_price * guilds_province_kill_request_percent +# other_difference_requests_price = difference_requests_price * other_province_kill_request_percent +# guild_return_province_kill_request_wage = total_return_pure_province_carcasses_price * guilds_province_kill_request_percent +# other_return_province_kill_request_wage = total_return_pure_province_carcasses_price * other_province_kill_request_percent +# +# company_province_kill_request_wage = ( +# total_pure_province_carcasses_price * company_province_kill_request_percent) + ( +# guilds_difference_requests_price + other_difference_requests_price) +# return_company_province_kill_request_wage = ( +# total_return_pure_province_carcasses_price * company_province_kill_request_percent) + ( +# guild_return_province_kill_request_wage + other_return_province_kill_request_wage) +# company_free_buying_live_wage = (( +# total_out_live_buying_province_carcasses_price - before_total_out_live_buying_province_carcasses_price) * company_free_buying_live_percent) + before_total_out_live_buying_province_carcasses_price +# company_free_buying_carcasses_wage = total_out_carcasses_buying_province_carcasses_price * company_free_buying_carcasses_percent +# company_free_sell_carcasses_wage = total_out_selling_province_carcasses_price * company_free_sell_carcasses_percent +# company_total_wage = company_province_kill_request_wage + company_free_buying_live_wage + company_free_buying_carcasses_wage + company_free_sell_carcasses_wage + company_out_province_poultry_request_wage + return_company_province_kill_request_wage +# company_total_paid_wage = slaughter_transactions.aggregate(total=Sum('company_share'))['total'] or 0 # company_total_paid_wage += poultry_transactions.aggregate(total=Sum('company_share'))['total'] or 0 +# # company_total_pure_paid_wage = company_total_paid_wage - (company_total_paid_wage * 0.08)) +# company_total_unpaid_wage = company_total_wage - company_total_paid_wage +# # shares_list.append({ # "name": "شرکت", # "out_province_poultry_request_wage": company_out_province_poultry_request_wage, @@ -5091,8 +4471,17 @@ class TotalWageInformationSerializer(serializers.ModelSerializer): # # }) # -# +# guilds_province_kill_request_wage = ( +# total_pure_province_carcasses_price * guilds_province_kill_request_percent) - guilds_difference_requests_price +# # return_guilds_province_kill_request_wage = total_return_pure_province_carcasses_price * guilds_province_kill_request_percent +# guilds_free_buying_live_wage = ( +# total_out_live_buying_province_carcasses_price - before_total_out_live_buying_province_carcasses_price) * guilds_free_buying_live_percent +# guilds_free_buying_carcasses_wage = total_out_carcasses_buying_province_carcasses_price * guilds_free_buying_carcasses_percent +# guilds_free_sell_carcasses_wage = total_out_selling_province_carcasses_price * guilds_free_sell_carcasses_percent +# guilds_total_wage = guilds_province_kill_request_wage + guilds_free_buying_live_wage + guilds_free_buying_carcasses_wage + guilds_free_sell_carcasses_wage + guilds_out_province_poultry_request_wage +# guilds_total_paid_wage = slaughter_transactions.aggregate(total=Sum('guilds_share'))['total'] or 0 # guilds_total_paid_wage += poultry_transactions.aggregate(total=Sum('guilds_share'))['total'] or 0 +# guilds_total_unpaid_wage = guilds_total_wage - guilds_total_paid_wage # # shares_list.append({ # "name": "صنف پروتئین", @@ -5108,8 +4497,17 @@ class TotalWageInformationSerializer(serializers.ModelSerializer): # # }) # -# +# other_province_kill_request_wage = ( +# total_pure_province_carcasses_price * other_province_kill_request_percent) - other_difference_requests_price +# # return_other_province_kill_request_wage = total_return_pure_province_carcasses_price * other_province_kill_request_percent +# other_free_buying_live_wage = ( +# total_out_live_buying_province_carcasses_price - before_total_out_live_buying_province_carcasses_price) * other_free_buying_live_percent +# other_free_buying_carcasses_wage = total_out_carcasses_buying_province_carcasses_price * other_free_buying_carcasses_percent +# other_free_sell_carcasses_wage = total_out_selling_province_carcasses_price * other_free_sell_carcasses_percent +# other_total_wage = other_province_kill_request_wage + other_free_buying_live_wage + other_free_buying_carcasses_wage + other_free_sell_carcasses_wage + other_out_province_poultry_request_wage +# other_total_paid_wage = slaughter_transactions.aggregate(total=Sum('other_share'))['total'] or 0 # other_total_paid_wage += poultry_transactions.aggregate(total=Sum('other_share'))['total'] or 0 +# other_total_unpaid_wage = other_total_wage - other_total_paid_wage # # shares_list.append({ # "name": "دامپزشک", @@ -5125,23 +4523,22 @@ class TotalWageInformationSerializer(serializers.ModelSerializer): # # }) # -# # return { # "wage_counting_type": wage_counting_type, -# "total_wage": total_wage, +# "total_wage": total_price, # "total_paid_wage": total_paid_wage, # "off": off, -# "total_unpaid_wage": total_wage - (total_paid_wage + off), +# "total_unpaid_wage": total_price - (total_paid_wage + off), # "out_province_poultry_request_weight": out_province_poultry_request_weight, # "out_province_poultry_request_wage": out_province_poultry_request_wage, # "province_kill_requests_total_wage": total_pure_province_carcasses_price, -# "province_kill_requests_total_weight": province_kill_requests_total_weight, +# "province_kill_requests_total_weight": total_pure_province_carcasses_weight, # "free_bars_live_total_wage": total_out_live_buying_province_carcasses_price, -# "free_bars_live_total_weight": free_bars_live_total_weight, +# "free_bars_live_total_weight": real_total_out_live_buying_province_carcasses_weight, # "free_bars_carcases_total_wage": total_out_carcasses_buying_province_carcasses_price, -# "free_bars_carcases_total_weight": free_bars_carcases_total_weight, +# "free_bars_carcases_total_weight": total_out_carcasses_buying_province_carcasses_weight, # "free_bars_out_province_carcases_total_wage": total_out_selling_province_carcasses_price, -# "free_bars_out_province_carcases_total_weight": free_bars_out_province_carcases_total_weight, +# "free_bars_out_province_carcases_total_weight": total_out_selling_province_carcasses_weight, # "total_province_live_weight": total_province_live_weight, # "total_province_carcasses_weight": total_province_carcasses_weight, # "province_live_wage_amount": province_live_wage_amount, @@ -5154,6 +4551,512 @@ class TotalWageInformationSerializer(serializers.ModelSerializer): # "return_total_province_live_weight": return_total_province_live_weight, # "total_return_pure_province_carcasses_price": total_return_pure_province_carcasses_price, # } +class TotalWageInformationSerializer(serializers.ModelSerializer): + wage_info = serializers.SerializerMethodField('get_wage_info') + + class Meta: + model = TotalWageInformation + fields = ['key', 'wage_info'] + + def get_wage_info(self, obj): + before_total_out_live_buying_province_carcasses_weight = 0 + after_total_out_live_buying_province_carcasses_weight = 0 + before_new_out_selling = 0 + after_new_out_selling = 0 + company_before_total_out_live_buying_province_carcasses_price = 0 + before_total_out_live_buying_province_carcasses_price = 0 + company_before_total_out_live_buying_province_carcasses_weight = 0 + extra_company_amount = 0 + total_weight = 0 + total_wage = 0 + total_paid_wage = 0 + shares_list = [] + total_unpaid_wage = 0 + union_total_weight = 0 + union_total_wage = 0 + union_total_paid_wage = 0 + union_total_unpaid_wage = 0 + union_province_kill_request_total_wage = 0 + freezing_union_province_kill_request_total_wage = 0 + union_kill_house_free_live_bar_total_wage = 0 + union_kill_house_free_carcases_bar_total_wage = 0 + union_chain_allocation_total_wage = 0 + union_province_kill_request_total_weight = 0 + freezing_union_province_kill_request_total_weight = 0 + union_kill_house_free_live_bar_total_weight = 0 + union_kill_house_free_carcases_bar_total_weight = 0 + union_chain_allocation_total_weight = 0 + + company_total_weight = 0 + company_total_wage = 0 + company_total_paid_wage = 0 + company_total_unpaid_wage = 0 + company_province_kill_request_total_wage = 0 + freezing_company_province_kill_request_total_wage = 0 + company_kill_house_free_live_bar_total_wage = 0 + company_kill_house_free_carcases_bar_total_wage = 0 + company_chain_allocation_total_wage = 0 + company_province_kill_request_total_weight = 0 + freezing_company_province_kill_request_total_weight = 0 + company_kill_house_free_live_bar_total_weight = 0 + company_kill_house_free_carcases_bar_total_weight = 0 + company_chain_allocation_total_weight = 0 + + guilds_total_weight = 0 + guilds_total_wage = 0 + guilds_total_paid_wage = 0 + guilds_total_unpaid_wage = 0 + guilds_province_kill_request_total_wage = 0 + freezing_guilds_province_kill_request_total_wage = 0 + guilds_kill_house_free_live_bar_total_wage = 0 + guilds_kill_house_free_carcases_bar_total_wage = 0 + guilds_chain_allocation_total_wage = 0 + guilds_province_kill_request_total_weight = 0 + freezing_guilds_province_kill_request_total_weight = 0 + guilds_kill_house_free_live_bar_total_weight = 0 + guilds_kill_house_free_carcases_bar_total_weight = 0 + guilds_chain_allocation_total_weight = 0 + + other_total_weight = 0 + other_total_wage = 0 + other_total_paid_wage = 0 + other_total_unpaid_wage = 0 + other_province_kill_request_total_wage = 0 + freezing_other_province_kill_request_total_wage = 0 + other_kill_house_free_live_bar_total_wage = 0 + other_kill_house_free_carcases_bar_total_wage = 0 + other_chain_allocation_total_wage = 0 + other_province_kill_request_total_weight = 0 + freezing_other_province_kill_request_total_weight = 0 + other_kill_house_free_live_bar_total_weight = 0 + other_kill_house_free_carcases_bar_total_weight = 0 + other_chain_allocation_total_weight = 0 + + province_kill_request_total_wage = 0 + province_kill_request_total_weight = 0 + freezing_province_kill_requests_total_wage = 0 + freezing_province_kill_requests_total_weight = 0 + chain_total_wage = 0 + chain_total_weight = 0 + free_bars_live_total_wage = 0 + free_bars_live_total_weight = 0 + free_bars_carcases_total_wage = 0 + free_bars_carcases_total_weight = 0 + real_free_sale_wage = 0 + union_real_free_sale_wage = 0 + company_real_free_sale_wage = 0 + guilds_real_free_sale_wage = 0 + other_real_free_sale_wage = 0 + total_check_wage = 0 + union_wage_percent = 0 + company_wage_percent = 0 + guilds_wage_percent = 0 + other_wage_percent = 0 + date1 = None + date2 = None + role = None + if self.context: + role = self.context.get('request').GET.get('role') + if self.context.get('request').GET.get('date1'): + date1 = datetime.strptime(str(self.context.get('request').GET['date1']), + '%Y-%m-%d').date() + date2 = datetime.strptime(str(self.context.get('request').GET['date2']), + '%Y-%m-%d').date() + + wage_type = WageType.objects.filter(en_name='province-kill-request').first() + total_check_wage = wage_type.amount + percentages_wage_type = PercentageOfWageType.objects.filter(wage_type=wage_type, percent__gt=0, trash=False) + for percentage_wage_type in percentages_wage_type: + if percentage_wage_type.share_type.en_name == 'union': + union_wage_percent = percentage_wage_type.percent / 100 + elif percentage_wage_type.share_type.en_name == 'company': + company_wage_percent = percentage_wage_type.percent / 100 + + elif percentage_wage_type.share_type.en_name == 'guilds': + guilds_wage_percent = percentage_wage_type.percent / 100 + elif percentage_wage_type.share_type.en_name in ['city', 'wallet']: + pass + else: + other_wage_percent = percentage_wage_type.percent / 100 + total_wage_type = WageType.objects.filter(trash=False) + province_live_wage_amount = total_wage_type.filter(en_name='province-kill-request', trash=False).first().amount + free_buying_live_weight_amount = total_wage_type.filter(en_name='live-buy', trash=False).first().amount + free_buying_carcesses_weight_amount = total_wage_type.filter(en_name='carcasse-buy', trash=False).first().amount + free_sell_carcesses_weight_amount = total_wage_type.filter(en_name='carcasse-sell', trash=False).first().amount + out_province_poultry_request_wage_amount = total_wage_type.filter(en_name='poultry-sell-out-province', + trash=False).first().amount + + if role == 'KillHouse': + try: + user = SystemUserProfile.objects.get(user=self.context.get('request').user) + except: + user = SystemUserProfile.objects.get(key=self.context.get('request').GET['key']) + kill_house = KillHouse.objects.filter(kill_house_operator__user=user, trash=False).first() + # if date1: + # finance_info = get_finance_info(kill_house, date1, date2) + # slaughter_transactions = InternalTransaction.objects.filter( + # Q(kill_house=kill_house) | Q(parent_kill_house=kill_house), date__date__gte=date1, + # date__date__lte=date2, status='completed', + # trash=False) + # + # else: + # finance_info = get_finance_info(kill_house) + # slaughter_transactions = InternalTransaction.objects.filter( + # Q(kill_house=kill_house) | Q(parent_kill_house=kill_house), status='completed', + # trash=False) + if date1: + finance_info = get_finance_info(kill_house, date1, date2) + if kill_house.killer and kill_house.type == 'public': + slaughter_transactions = InternalTransaction.objects.filter( + kill_house=kill_house,parent_kill_house=kill_house, date__date__gte=date1, + date__date__lte=date2, status='completed', + trash=False) + else: + slaughter_transactions = InternalTransaction.objects.filter( + Q(kill_house=kill_house) | Q(parent_kill_house=kill_house), date__date__gte=date1, + date__date__lte=date2, status='completed', + trash=False) + + else: + finance_info = get_finance_info(kill_house) + if kill_house.killer and kill_house.type == 'public': + + slaughter_transactions = InternalTransaction.objects.filter( + kill_house=kill_house,parent_kill_house=kill_house, status='completed', + trash=False) + else: + slaughter_transactions = InternalTransaction.objects.filter( + Q(kill_house=kill_house) | Q(parent_kill_house=kill_house), status='completed', + trash=False) + + total_paid_wage += slaughter_transactions.aggregate(total=Sum('amount'))[ + 'total'] or 0 + + return { + "wage_counting_type": wage_counting_type, + "total_wage": finance_info['total_price'], + "total_paid_wage": total_paid_wage, + "off": kill_house.off, + "total_unpaid_wage": finance_info['total_price'] - (total_paid_wage + kill_house.off), + "province_kill_requests_total_wage": finance_info['total_pure_province_carcasses_price'], + "province_kill_requests_total_weight": finance_info['total_pure_province_carcasses_weight'], + "free_bars_live_total_wage": finance_info['total_out_live_buying_province_carcasses_price'], + "free_bars_live_total_weight": finance_info['total_out_live_buying_province_carcasses_weight'], + "free_bars_carcases_total_wage": finance_info['total_out_carcasses_buying_province_carcasses_price'], + "free_bars_carcases_total_weight": finance_info['total_out_carcasses_buying_province_carcasses_weight'], + "free_bars_out_province_carcases_total_wage": finance_info[ + 'total_out_selling_province_carcasses_price'], + "free_bars_out_province_carcases_total_weight": finance_info[ + 'total_out_selling_province_carcasses_weight'], + "total_province_live_weight": finance_info['total_province_live_weight'], + "total_province_carcasses_weight": finance_info['total_province_carcasses_weight'], + "province_live_wage_amount": province_live_wage_amount, + "free_buying_live_weight_amount": free_buying_live_weight_amount, + "free_buying_carcesses_weight_amount": free_buying_carcesses_weight_amount, + "free_sell_carcesses_weight_amount": free_sell_carcesses_weight_amount, + "finance_info": finance_info, + "return_total_province_live_weight": finance_info['return_total_province_live_weight'], + "total_return_pure_province_carcasses_price": finance_info[ + 'total_return_pure_province_carcasses_price'], + } + + elif role == 'ChainCompany': + try: + user = SystemUserProfile.objects.get(user=self.context.get('request').user) + except: + user = SystemUserProfile.objects.get(key=self.context.get('request').GET['key']) + chain_company = ChainCompany.objects.get(user=user, trash=False) + chain_allocations = ChainAllocation.objects.filter(chain_company=chain_company, state='accepted', + trash=False) + chain_allocations_total_wage = chain_allocations.aggregate(total=Sum('total_wage_amount'))[ + 'total'] or 0 + total_wage += chain_allocations_total_wage + chain_allocations_total_weight = chain_allocations.aggregate(total=Sum('weight'))[ + 'total'] or 0 + total_weight += chain_allocations_total_weight + + chain_company_transactions = InternalTransaction.objects.filter(chain_company=chain_company, + status='completed', trash=False) + total_paid_wage += chain_company_transactions.aggregate(total=Sum('amount'))[ + 'total'] or 0 + + return { + "total_weight": total_weight, + "total_wage": total_wage, + "chain_allocations_total_wage": chain_allocations_total_wage, + "chain_allocations_total_weight": chain_allocations_total_weight, + "total_paid_wage": total_paid_wage, + "total_unpaid_wage": total_wage - total_paid_wage + } + + + + + else: + + total_wage=0 + total_paid_wage=0 + off=0 + out_province_poultry_request_weight=0 + out_province_poultry_request_wage=0 + total_pure_province_carcasses_price=0 + province_kill_requests_total_weight=0 + total_out_live_buying_province_carcasses_price=0 + free_bars_live_total_weight=0 + total_out_carcasses_buying_province_carcasses_price=0 + free_bars_carcases_total_weight=0 + total_out_selling_province_carcasses_price=0 + free_bars_out_province_carcases_total_weight=0 + total_province_live_weight=0 + total_province_carcasses_weight=0 + extra_company_amount=0 + shares_list=[] + return_total_province_live_weight=0 + total_return_pure_province_carcasses_price=0 + + + + + + total_union_province_kill_request_wage=0 + total_union_return_province_kill_request_wage=0 + total_union_free_buying_live_wage=0 + total_union_free_buying_carcasses_wage=0 + total_union_free_sell_carcasses_wage=0 + total_union_total_wage=0 + total_union_total_paid_wage=0 + total_union_total_unpaid_wage=0 + + total_company_province_kill_request_wage=0 + total_company_return_province_kill_request_wage=0 + total_company_free_buying_live_wage=0 + total_company_free_buying_carcasses_wage=0 + total_company_free_sell_carcasses_wage=0 + total_company_total_wage=0 + total_company_total_paid_wage=0 + total_company_total_unpaid_wage=0 + + + total_guilds_province_kill_request_wage=0 + total_guilds_return_province_kill_request_wage=0 + total_guilds_free_buying_live_wage=0 + total_guilds_free_buying_carcasses_wage=0 + total_guilds_free_sell_carcasses_wage=0 + total_guilds_total_wage=0 + total_guilds_total_paid_wage=0 + total_guilds_total_unpaid_wage=0 + + total_other_province_kill_request_wage=0 + total_other_return_province_kill_request_wage=0 + total_other_free_buying_live_wage=0 + total_other_free_buying_carcasses_wage=0 + total_other_free_sell_carcasses_wage=0 + total_other_total_wage=0 + total_other_total_paid_wage=0 + total_other_total_unpaid_wage=0 + + if date1: + poultry_transactions = InternalTransaction.objects.filter( + poultry__isnull=False, status='completed', date__date__gte=date1, date__date__lte=date2, + trash=False) + + poultry_requests = PoultryRequest.objects.filter(trash=False, state_process__in=('pending', 'accepted'), + province_state__in=('pending', 'accepted'), out=True, + out_province_request_cancel=False, + temporary_trash=False, send_date__date__gte=date1, + send_date__date__lte=date2, + wage_pay=True, has_wage=True, + temporary_deleted=False) + + else: + poultry_transactions = InternalTransaction.objects.filter( + poultry__isnull=False, status='completed', + trash=False) + + poultry_requests = PoultryRequest.objects.filter(trash=False, state_process__in=('pending', 'accepted'), + province_state__in=('pending', 'accepted'), out=True, + out_province_request_cancel=False, + temporary_trash=False, + wage_pay=True, has_wage=True, + temporary_deleted=False) + + + out_province_poultry_request_weight = \ + poultry_requests.aggregate(total=Sum(F('quantity') * F('Index_weight')))[ + 'total'] or 0 + out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('total_wage_amount'))[ + 'total'] or 0 + union_out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('union_share'))[ + 'total'] or 0 + company_out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('company_share'))[ + 'total'] or 0 + guilds_out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('guilds_share'))[ + 'total'] or 0 + other_out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('other_share'))[ + 'total'] or 0 + total_paid_wage = poultry_transactions.aggregate(total=Sum('amount'))[ + 'total'] or 0 + total_union_total_paid_wage += poultry_transactions.aggregate(total=Sum('union_share'))['total'] or 0 + total_company_total_paid_wage += poultry_transactions.aggregate(total=Sum('company_share'))['total'] or 0 + total_guilds_total_paid_wage += poultry_transactions.aggregate(total=Sum('guilds_share'))['total'] or 0 + total_other_total_paid_wage += poultry_transactions.aggregate(total=Sum('other_share'))['total'] or 0 + + + + + total_wage +=out_province_poultry_request_wage + # kill_houses = KillHouse.objects.filter(out_province=False, trash=False).order_by('id') + kill_house_ids = KillHousePercentage.objects.filter(kill_house__type='exclusive', trash=False).values_list( + 'kill_house', flat=True) + kill_houses = KillHouse.objects.filter(out_province=False, trash=False).exclude( + id__in=kill_house_ids).order_by( + 'id') + for kill_house in kill_houses: + finance_info =get_total_wage_info(kill_house) + + total_wage += finance_info['total_wage'] + total_paid_wage += finance_info['total_paid_wage'] + off += finance_info['off'] + # out_province_poultry_request_weight += finance_info['total_wage'] + # out_province_poultry_request_wage += finance_info['total_wage'] + total_pure_province_carcasses_price += finance_info['province_kill_requests_total_wage'] + province_kill_requests_total_weight += finance_info['province_kill_requests_total_weight'] + total_out_live_buying_province_carcasses_price += finance_info['free_bars_live_total_wage'] + free_bars_live_total_weight += finance_info['free_bars_live_total_weight'] + total_out_carcasses_buying_province_carcasses_price += finance_info['free_bars_carcases_total_wage'] + free_bars_carcases_total_weight += finance_info['free_bars_carcases_total_weight'] + total_out_selling_province_carcasses_price += finance_info['free_bars_out_province_carcases_total_wage'] + free_bars_out_province_carcases_total_weight += finance_info['free_bars_out_province_carcases_total_weight'] + total_province_live_weight += finance_info['total_province_live_weight'] + total_province_carcasses_weight += finance_info['total_province_carcasses_weight'] + extra_company_amount += finance_info['extra_company_amount'] + return_total_province_live_weight += finance_info['return_total_province_live_weight'] + total_return_pure_province_carcasses_price += finance_info['total_return_pure_province_carcasses_price'] + total_union_province_kill_request_wage += finance_info['union_province_kill_request_wage'] + total_union_return_province_kill_request_wage += finance_info['return_union_province_kill_request_wage'] + total_union_free_buying_live_wage += finance_info['union_free_buying_live_wage'] + total_union_free_buying_carcasses_wage += finance_info['union_free_buying_carcasses_wage'] + total_union_free_sell_carcasses_wage += finance_info['union_free_sell_carcasses_wage'] + total_union_total_wage += finance_info['union_total_wage'] + total_union_total_paid_wage += finance_info['union_total_paid_wage'] + total_union_total_unpaid_wage += finance_info['union_total_unpaid_wage'] + + total_company_province_kill_request_wage += finance_info['company_province_kill_request_wage'] + total_company_return_province_kill_request_wage += finance_info['return_company_province_kill_request_wage'] + total_company_free_buying_live_wage += finance_info['company_free_buying_live_wage'] + total_company_free_buying_carcasses_wage += finance_info['company_free_buying_carcasses_wage'] + total_company_free_sell_carcasses_wage += finance_info['company_free_sell_carcasses_wage'] + total_company_total_wage += finance_info['company_total_wage'] + total_company_total_paid_wage += finance_info['company_total_paid_wage'] + total_company_total_unpaid_wage += finance_info['company_total_unpaid_wage'] + + total_guilds_province_kill_request_wage += finance_info['guilds_province_kill_request_wage'] + total_guilds_return_province_kill_request_wage += finance_info['return_guilds_province_kill_request_wage'] + total_guilds_free_buying_live_wage += finance_info['guilds_free_buying_live_wage'] + total_guilds_free_buying_carcasses_wage += finance_info['guilds_free_buying_carcasses_wage'] + total_guilds_free_sell_carcasses_wage += finance_info['guilds_free_sell_carcasses_wage'] + total_guilds_total_wage += finance_info['guilds_total_wage'] + total_guilds_total_paid_wage += finance_info['guilds_total_paid_wage'] + total_guilds_total_unpaid_wage += finance_info['guilds_total_unpaid_wage'] + + total_other_province_kill_request_wage += finance_info['other_province_kill_request_wage'] + total_other_return_province_kill_request_wage += finance_info['return_other_province_kill_request_wage'] + total_other_free_buying_live_wage += finance_info['other_free_buying_live_wage'] + total_other_free_buying_carcasses_wage += finance_info['other_free_buying_carcasses_wage'] + total_other_free_sell_carcasses_wage += finance_info['other_free_sell_carcasses_wage'] + total_other_total_wage += finance_info['other_total_wage'] + total_other_total_paid_wage += finance_info['other_total_paid_wage'] + total_other_total_unpaid_wage += finance_info['other_total_unpaid_wage'] + + shares_list.append({ + "name": "اتحادیه", + "out_province_poultry_request_wage": union_out_province_poultry_request_wage, + "province_kill_request_wage": total_union_province_kill_request_wage, + "return_province_kill_request_wage": total_union_return_province_kill_request_wage, + "free_buying_live_wage": total_union_free_buying_live_wage, + "free_buying_carcasses_wage": total_union_free_buying_carcasses_wage, + "free_sell_carcasses_wage": total_union_free_sell_carcasses_wage, + "total_wage": total_union_total_wage, + "total_paid_wage": total_union_total_paid_wage, + "total_unpaid_wage": total_union_total_unpaid_wage, + + }) + + shares_list.append({ + "name": "شرکت", + "out_province_poultry_request_wage": company_out_province_poultry_request_wage, + "province_kill_request_wage": total_company_province_kill_request_wage, + "return_province_kill_request_wage": total_company_return_province_kill_request_wage, + "free_buying_live_wage": total_company_free_buying_live_wage, + "free_buying_carcasses_wage": total_company_free_buying_carcasses_wage, + "free_sell_carcasses_wage": total_company_free_sell_carcasses_wage, + "total_wage": total_company_total_wage, + "total_paid_wage": total_company_total_paid_wage, + "total_unpaid_wage": total_company_total_unpaid_wage, + + }) + + shares_list.append({ + "name": "صنف پروتئین", + "out_province_poultry_request_wage": guilds_out_province_poultry_request_wage, + "province_kill_request_wage": total_guilds_province_kill_request_wage, + "return_province_kill_request_wage": 0, + "free_buying_live_wage": total_guilds_free_buying_live_wage, + "free_buying_carcasses_wage": total_guilds_free_buying_carcasses_wage, + "free_sell_carcasses_wage": total_guilds_free_sell_carcasses_wage, + "total_wage": total_guilds_total_wage, + "total_paid_wage": total_guilds_total_paid_wage, + "total_unpaid_wage": total_guilds_total_unpaid_wage, + + }) + + + + shares_list.append({ + "name": "دامپزشک", + "out_province_poultry_request_wage": other_out_province_poultry_request_wage, + "province_kill_request_wage": total_other_province_kill_request_wage, + "return_province_kill_request_wage": 0, + "free_buying_live_wage": total_other_free_buying_live_wage, + "free_buying_carcasses_wage": total_other_free_buying_carcasses_wage, + "free_sell_carcasses_wage": total_other_free_sell_carcasses_wage, + "total_wage": total_other_total_wage, + "total_paid_wage": total_other_total_paid_wage, + "total_unpaid_wage": total_other_total_unpaid_wage, + + }) + + + + + return { + "wage_counting_type": wage_counting_type, + "total_wage": total_wage, + "total_paid_wage": total_paid_wage, + "off": off, + "total_unpaid_wage": total_wage - (total_paid_wage + off), + "out_province_poultry_request_weight": out_province_poultry_request_weight, + "out_province_poultry_request_wage": out_province_poultry_request_wage, + "province_kill_requests_total_wage": total_pure_province_carcasses_price, + "province_kill_requests_total_weight": province_kill_requests_total_weight, + "free_bars_live_total_wage": total_out_live_buying_province_carcasses_price, + "free_bars_live_total_weight": free_bars_live_total_weight, + "free_bars_carcases_total_wage": total_out_carcasses_buying_province_carcasses_price, + "free_bars_carcases_total_weight": free_bars_carcases_total_weight, + "free_bars_out_province_carcases_total_wage": total_out_selling_province_carcasses_price, + "free_bars_out_province_carcases_total_weight": free_bars_out_province_carcases_total_weight, + "total_province_live_weight": total_province_live_weight, + "total_province_carcasses_weight": total_province_carcasses_weight, + "province_live_wage_amount": province_live_wage_amount, + "free_buying_live_weight_amount": free_buying_live_weight_amount, + "free_buying_carcesses_weight_amount": free_buying_carcesses_weight_amount, + "free_sell_carcesses_weight_amount": free_sell_carcesses_weight_amount, + "out_province_poultry_request_wage_amount": out_province_poultry_request_wage_amount, + "extra_company_amount": extra_company_amount, + "shares": shares_list, + "return_total_province_live_weight": return_total_province_live_weight, + "total_return_pure_province_carcasses_price": total_return_pure_province_carcasses_price, + } class ParentCompanyTotalWageInformationSerializer(serializers.ModelSerializer):